473,748 Members | 2,670 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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="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>

Jul 23 '05 #1
4 4131
"mitch-co2" <mi*******@yaho o.com> wrote in message
news:11******** **************@ o13g2000cwo.goo glegroups.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="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>


Will this help? Watch for word-wrap.

<html>
<head>
<title>RadioYes .htm</title>
<script type="text/javascript">
function setField(form,w hat) {
(what == 1) ? form.myText.val ue = form.date.value : form.myText.val ue =
"";
}
</script>
</head>
<body>
<form>
Yes <input name="myTick" type="radio" value="Yes"
onClick="setFie ld(this.form,1) ">
No <input name="myTick" type="radio" value="No"
onClick="setFie ld(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="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 : &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*******@yaho o.com> wrote in message
news:11******** **************@ o13g2000cwo.goo glegroups.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="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>

Will this help? Watch for word-wrap.

<html>
<head>
<title>RadioYes .htm</title>
<script type="text/javascript">
function setField(form,w hat) {
(what == 1) ? form.myText.val ue = form.date.value :

form.myText.val ue = "";
}
</script>
</head>
<body>
<form>
Yes <input name="myTick" type="radio" value="Yes"
onClick="setFie ld(this.form,1) ">
No <input name="myTick" type="radio" value="No"
onClick="setFie ld(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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
6163
by: sman | last post by:
Hi, I recently read this article on About.com on how to create required fields for a form: http://javascript.about.com/library/scripts/blformvalidate.htm Everything works great except that there are no instructions on how to make checkboxes and radio buttons required. I've tried adding these to my form, but I'm having no luck. Anyone know how to add radio buttons and checkboxes using the existing code mentioned on the url? Thank you!
10
13459
by: DettCom | last post by:
Hello, I would like to be able to display or hide fields based on whether a specific Yes/No radio button is selected. This is in conjunction with a posting a just made here in the same group related to checkboxes. Thanks!!!
3
2371
by: ewitkop90 | last post by:
Here is my code: <SCRIPT> function transportchange(transport) { if (framenewinstall.Helpdesk.checked) framenewinstall.Helpdesk.checked=false; if (framenewinstall.CircuitNumber.checked) framenewinstall.CircuitNumber.checked=false; switch (transport) { case 0: Helpdesk.innerText="No Info Needed";
5
3108
by: Digital Puer | last post by:
I have the following HTML form: - radio button A (default selected) - radio button B - input field, of type "file" with "Choose" button - submit button I would like to have it so that if the user clicks on the "Choose" button of the input field (to select a file on the local disk), then radio button B is automatically
6
3873
by: Orchid | last post by:
I have 2 fields with Radio button Data Type, and both fields with more than one options. On Field1, I want the user to select option1, then Field2 is shown and able to select. If the user selects Option2, then Field2 is not shown. I can have the hidden-field working properly. However, after the user selected Field1-Option1 and selected an Option on Field2, but cannot deselect the option on Field2 if change mind on Field1 selection. ...
1
3352
by: FunkHouse9 | last post by:
I'm trying to develop an order page and in one section, the customer specifies a shipment type using radio buttons that is submitted to the shopping cart. There are 4 buttons. If either of the first two are selected, the form should submit the data. If either of the last two are selected, I want the form to require input on a text field to collect an account number (op40_LabelShip). I have gotten the form to require the field, but it...
5
4155
by: Fran Jakers | last post by:
Hello all, I'm new to all this and I could really use some help. I've searched the web but cannot find an answer. I have an HTML form with 3 radio buttons and a search field that calls a MySQL database using JavaScript to find a product either by Product ID, Description, or Both. Originally, the 'Both' radio button was "checked" but I now want the 'Product ID' button set as the default choice (as you can see from the code below). ...
6
2074
by: dba | last post by:
using the following code with a problem.... echo "<input type='hidden' name='member_id' value=\"{$row}\">{$row}"; echo "<input type='radio' name='member_name' value=\"{$row}\">{$row}<br />"; The post_data.php program posts the following member id is: 0009
4
3026
by: pureadrenaline | last post by:
Hey Guys, Please could anyone help me out with the following form I need to create a validation on the email field only if the user checked the radio button named Email. Thanks in advance. <form action="" method="get"> <div align="center"> <table border="0" cellspacing="0" cellpadding="0">
0
8832
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9381
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8252
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6799
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4608
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4879
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3316
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2791
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2217
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.