By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,148 Members | 748 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,148 IT Pros & Developers. It's quick & easy.

radio button make text field equal value of form field

P: n/a
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
Share this Question
Share on Google+
4 Replies


P: n/a
"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

P: n/a
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

P: n/a
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

P: n/a
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.