Connecting Tech Pros Worldwide Forums | Help | Site Map

radio button make text field equal value of form field

mitch-co2
Guest
 
Posts: n/a
#1: Jul 23 '05
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>


McKirahan
Guest
 
Posts: n/a
#2: Jul 23 '05

re: radio button make text field equal value of form field


"mitch-co2" <mitch_001@yahoo.com> wrote in message
news:1109025468.500165.322690@o13g2000cwo.googlegr oups.com...[color=blue]
> 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>
>[/color]

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>


RobG
Guest
 
Posts: n/a
#3: Jul 23 '05

re: radio button make text field equal value of form field


mitch-co2 wrote:[color=blue]
> 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>
>[/color]

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
mitch-co2
Guest
 
Posts: n/a
#4: Jul 23 '05

re: radio button make text field equal value of form field


McKirahan,

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

Mitch



McKirahan wrote:[color=blue]
> "mitch-co2" <mitch_001@yahoo.com> wrote in message
> news:1109025468.500165.322690@o13g2000cwo.googlegr oups.com...[color=green]
> > What I am trying to do is when someone clicks on the YES radio[/color][/color]
button I[color=blue][color=green]
> > want the text field called MYTEXT to equal the text field named[/color][/color]
DATE.[color=blue][color=green]
> >
> > 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>
> >[/color]
>
> 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 :[/color]
form.myText.value =[color=blue]
> "";
> }
> </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>[/color]

mitch-co2
Guest
 
Posts: n/a
#5: Jul 23 '05

re: radio button make text field equal value of form field


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

Closed Thread