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 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
|
<script type="text/javascript"><!-- hide from old browsers
// turn on/off any "other"fields
function fb_other_on (othername) {
var box = document.getElementById(othername);
box.removeAttribute('disabled');
}
function fb_other_off (othername) {
var box = document.getElementById(othername);
box.setAttribute('disabled', 'disabled');
}
function validate (form) {
var alertstr = '';
var invalid = 0;
// favorite_color: radio group or multiple checkboxes
var favorite_color = null;
var selected_favorite_color = 0;
for (var loop = 0; loop < form.elements['favorite_color'].length; loop++) {
if (form.elements['favorite_color'][loop].checked) {
favorite_color = form.elements['favorite_color'][loop].value;
selected_favorite_color++;
if (favorite_color == '_other_favorite_color') favorite_color = form.elements['_other_favorite_color'].value;
if (favorite_color != null && favorite_color != "" && ! favorite_color.match(/^[a-zA-Z]+$/)) {
alertstr += '- Invalid entry for the "Favorite Color" field\n';
invalid++;
}
} // if
} // for favorite_color
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>
<noscript><font color="#cc0000"><b>Please enable Javascript or use a newer browser.</b></font></noscript>
<form action="TEST" method="get" onsubmit="return validate(this);">
<div>
<input id="_submitted" name="_submitted" type="hidden" value="1" />
<table>
<tr valign="top">
<td>Favorite Color</td>
<td><table>
<tr>
<td><input id="favorite_color_red" name="favorite_color" onclick="fb_other_off('_other_favorite_color')" type="radio" value="red" /></td>
<td><label for="favorite_color_red">red</label></td>
</tr>
<tr>
<td><input id="favorite_color_green" name="favorite_color" onclick="fb_other_off('_other_favorite_color')" type="radio" value="green" /></td>
<td><label for="favorite_color_green">green</label></td>
</tr>
<tr>
<td><input id="favorite_color_blue" name="favorite_color" onclick="fb_other_off('_other_favorite_color')" type="radio" value="blue" /></td>
<td><label for="favorite_color_blue">blue</label></td>
</tr>
<tr>
<td><input id="favorite_color_yellow" name="favorite_color" onclick="fb_other_off('_other_favorite_color')" type="radio" value="yellow" /></td>
<td><label for="favorite_color_yellow">yellow</label></td>
</tr>
<tr>
<td><input id="_favorite_color" name="favorite_color" onclick="fb_other_on('_other_favorite_color')" type="radio" value="_other_favorite_color" /></td>
<td><label for="_favorite_color">Other:</label></td>
</tr>
</table> <input disabled="disabled" id="_other_favorite_color" name="_other_favorite_color" type="text" /></td>
</tr>
<tr valign="top">
<td align="center" colspan="2"><input id="_submit" name="_submit" type="submit" value="Submit" /></td>
</tr>
</table>
</div>
</form>
|