1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
|
<html>
<title>User Info</title>
Please update your info and hit "Submit".
<script type="text/javascript"><!-- hide from old browsers
function validate (form) {
var alertstr = '';
var invalid = 0;
// color: radio group or multiple checkboxes
var color = null;
var selected_color = 0;
for (var loop = 0; loop < form.elements['color'].length; loop++) {
if (form.elements['color'][loop].checked) {
color = form.elements['color'][loop].value;
selected_color++;
if (color == null || (color != 'red' && color != 'blue' && color != 'yellow' && color != 'pink')) {
alertstr += '- Check one or more of the "Color" options\n';
invalid++;
}
} // if
} // for color
if (! selected_color) {
alertstr += '- Check one or more of the "Color" options\n';
invalid++;
}
if (invalid > 0 || alertstr != '') {
if (! invalid) invalid = 'The following'; // catch for programmer error
alert(''+invalid+' error(s) were encountered with your submission:'+'\n\n'
+alertstr+'\n'+'Please correct these fields and try again.');
// reset counters
alertstr = '';
invalid = 0;
return false;
}
return true; // all checked ok
}
//-->
</script>
<p>
<form action="TEST" method="get" onsubmit="return validate(this);"><input id="_submitted" name="_submitted" type="hidden" value="1" />
Enter your name: <input id="name" name="name" type="text" />
<select name="color" multiple>
<option value="red" >1</option>
<option value="blue" >2</option>
<option value="yellow" selected>3</option>
<option value="pink" >4</option>
</select>
FYI, your dress size is (unknown)<br>
<input id="_submit" name="_submit" onclick="this.form._submit.value = this.value;" type="submit" value="Update" /><input id="_submit_2" name="_submit" onclick="this.form._submit.value = this.value;" type="submit" value="Delete" />
</form>
|