I have a form that deletes a a value once the user has confirmed the action via a javascript confirm. This works well but I would also like the script to alert the user if the value was empty therefore stopping the script from running altogether.
<script>
function delete_confirm() {
var msg = confirm('Are you sure you want to delete the selected audit');
if (msg == false) {
return false;
}
}
</script>
<form id="audit_control_form" method="post"
action="<?php echo $_SERVER['PHP_SELF']; ?>">
<select id="audit_id_select" name="audit_id_select" style="width:150px">
<option value="">Please select</option>
<? while ($row = mysqli_fetch_assoc($result)) {
if ($row['dateEnd'] == '0000-00-00') {
$dateEnd = 'Present';
} else {
$dateEnd = date('d-m-Y', strtotime($row['dateEnd']));
}
echo '<option value="'.$row['auditID'].'">'.$row['auditName']
.' (' . date('d-m-Y', strtotime($row['dateStart']))
.' - '.$dateEnd . ')</option>';
} ?>
</select>
<input type="submit" name="audit_delete_submit"
onClick="return delete_confirm()" value="Delete" />
</form>
I am not sure what is the best way to implement this (I'm fairly new to javascript).