radio button make text field equal value of form field

M

mitch-co2

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="JavaScript"><!--
function setField(what) {
if (what.myTick.checked)
what.myText.value = what.date.value;
else
what.myText.value = '';
}
//--></script>

<form>
<p>
Yes <input name="myTick" type="radio" value="Yes"
onClick="setField(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>
 
M

McKirahan

mitch-co2 said:
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="JavaScript"><!--
function setField(what) {
if (what.myTick.checked)
what.myText.value = what.date.value;
else
what.myText.value = '';
}
//--></script>

<form>
<p>
Yes <input name="myTick" type="radio" value="Yes"
onClick="setField(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>

Will this help? Watch for word-wrap.

<html>
<head>
<title>RadioYes.htm</title>
<script type="text/javascript">
function setField(form,what) {
(what == 1) ? form.myText.value = form.date.value : form.myText.value =
"";
}
</script>
</head>
<body>
<form>
Yes <input name="myTick" type="radio" value="Yes"
onClick="setField(this.form,1)">
No <input name="myTick" type="radio" value="No"
onClick="setField(this.form,0)">
<br>sample date : &nbsp;
<input type="text" name="date" value="20050202">
<br>auto fill in : &nbsp;
<input type="text" name="myText">
</form>
</body>
</html>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top