473,703 Members | 3,300 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 4125
"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
6159
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
13456
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
2369
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
3107
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
3870
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
3343
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
4154
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
2071
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
3025
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
8759
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9252
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9017
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8966
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7872
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
6588
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
5922
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4687
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2070
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.