Peach wrote:
What a brilliant man! Thanks. Works like a charm.
Here's another one, based on RobB's example, that modifies the
checked radio buttons so only one 'yes' is ever checked and all
the rest are 'no'.
It may suit ... or not.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>one yes</title>
<script type="text/javascript">
function initForm(f){
var els = document.forms[f].elements;
var i = els.length;
while (i--) {
if (/radio/.test(els[i].type)
&& /yes/i.test(els[i].value)) {
els[i].onclick = function() {
var j = els.length
var el = els[j];
while (j--) {
var el = els[j];
if ( /radio/.test(el.type)
&& /yes/i.test(el.value)
&& el.checked
&& el != this) {
// Put up alert if wanted...
toggleYes(el);
}
}
}; // end of function
}
}
}
// Set current radio to off,
// next 'no' radio to on
function toggleYes(el){
el.checked = false;
while ( el.nextSibling // Prevent endless loop
&& ( !/radio/.test(el.type)
|| !/no/i.test(el.value))) {
el = el.nextSibling;
}
el.checked = true;
}
</script>
</head>
<body onload="initForm('q');">
<form name="q" action="">
<ol>
<li><input type="radio" name="Q1" value="yes">yes
<input type="radio" name="Q1" value="no"
checked="checked">no</li><br>
<li><input type="radio" name="Q2" value="yes">yes
<input type="radio" name="Q2" value="no"
checked="checked">no</li><br>
<li><input type="radio" name="Q3" value="yes">yes
<input type="radio" name="Q3" value="no"
checked="checked">no</li><br>
<li><input type="radio" name="Q4" value="yes">yes
<input type="radio" name="Q4" value="no"
checked="checked">no</li><br>
</ol>
<input type="reset">
</form>
</body>
</html>
--
Rob