Click to See Complete Forum and Search --> : selectboxes


freshb
12-19-2003, 07:48 AM
Hi I have a quick question involving form validation, and for some reason I cant find an appropriate answer in the archives. I have a select box where the 'selected' value (which is just a command choice) is "ALL". The rest of the options in the box are populated via a dynamic query in ColdFusion. All I need to do is write a quick validation script to be sure that if the form is submitted with the default choice ("ALL") being highlighted, and alert box pops up with an error message.

Any help would be greatly appreciated, or even a link to an area of the archives where this has already been discussed that I may have missed.

Thanks in advance!

Pittimann
12-19-2003, 09:07 AM
Hi!

There are fifferent ways to do this. Here is one:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Untitled</title>
<script language="JavaScript" type="text/javascript">
<!--
function checkForm(){
if (document.myForm.whatToDo.value=="ALL"){
alert("Please select an option!");
return false;
}
else{
alert("OK");
return true;
}
}
//-->
</script>
</head>
<body>
<form name="myForm" onSubmit="return checkForm()">
<select name="whatToDo">
<option value="ALL" selected>ALL</option>
<option value="notALL1">notALL1</option>
<option value="notALL2">notALL2</option>
<option value="notALL3">notALL3</option>
</select>
<input type="submit" value="Submit">
</form>
</body>
</html>

Cheers - Pit

freshb
12-19-2003, 09:13 AM
This is exactly what I was looking for. Thanks!!

Pittimann
12-19-2003, 09:17 AM
Hi!

You are welcome!

Cheers - Pit