mitch-co2 wrote:
What I am trying to do is when someone clicks on the YES radio button I
want the text field called MYTEXT to equal the text field named DATE.
The below code works as long as I do NOT UN-COMMENT the NO radio
button, once I do that it will not work.
Any help would be greatly appreciated.
Mitch
<body>
<script language="JavaS cript"><!--
function setField(what) {
if (what.myTick.ch ecked)
what.myText.val ue = what.date.value ;
else
what.myText.val ue = '';
}
//--></script>
<form>
<p>
Yes <input name="myTick" type="radio" value="Yes"
onClick="setFie ld(this.form)">
<!-- No <input name="myTick" type="radio" value="No"> -->
</p>
<p>sample date
<input type="text" name="date" value="20050202 ">
auto fill in
<input type="text" name="myText">
</p>
</form>
</body>
This is, to me, an incorrect use of a radio button. A better
control to use is a checkbox. The issues with using a radio
button for simple on/off, yes/no logic are below.
One button should always be selected. If one is not specified as
"checked", browser behaviour is not defined on whether or not
to make one checked. The HTML 4 spec and RFC1866 differ on this
point. If neither Yes or No are checked, what is the state of
the control?
<URL:http://www.w3.org/TR/html4/interact/forms.html#radi o>
I guess in this case the 'No' button should be checked.
Additionally, if there are only two states - yes/no - only one
'button' is needed - a checkbox. Now the default state can be
off (equivalent to resetting the no radio to checked) and only
one control is needed, only one event is required and the logic
is simplified.
<html><head>
<title>RadioYes .htm</title>
<script type="text/javascript">
function copyConditional (c,i1,i2) {
(c.checked)? i2.value=i1.val ue : i2.value='';
}
</script>
</head>
<body>
<form>
Copy date to other field?
<input name="dateCopy" type="checkbox" onClick="
copyConditional (this,
this.form.date,
this.form.myTex t);
">
<br>sample date :
<input type="text" name="date" value="2005-02-02">
<br>auto fill in :
<input type="text" name="myText">< br>
<input type="reset">
</form>
</body>
</html>
--
Rob