471,852 Members | 1,239 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,852 software developers and data experts.

radio button make text field equal value of form field

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>

Jul 23 '05 #1
4 3998
"mitch-co2" <mi*******@yahoo.com> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.com...
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>
Jul 23 '05 #2
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="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>


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#radio>

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.value : i2.value='';
}
</script>
</head>
<body>
<form>
Copy date to other field?
<input name="dateCopy" type="checkbox" onClick="
copyConditional(this,
this.form.date,
this.form.myText);
">
<br>sample date : &nbsp;
<input type="text" name="date" value="2005-02-02">
<br>auto fill in : &nbsp;
<input type="text" name="myText"><br>
<input type="reset">
</form>
</body>
</html>
--
Rob
Jul 23 '05 #3
McKirahan,

Thank you very much for the help...it worked perfectly!

Mitch

McKirahan wrote:
"mitch-co2" <mi*******@yahoo.com> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.com...
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>


Jul 23 '05 #4
RobG,

What can I say, I have to do what the client wants regardless of what I
think. And yes...I agree with you! :-)

Mitch

Jul 23 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

10 posts views Thread by DettCom | last post: by
5 posts views Thread by Digital Puer | last post: by
NeoPa
reply views Thread by NeoPa | last post: by
aboka
reply views Thread by aboka | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.