473,765 Members | 2,047 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

real time display of radio button input array

Hi,
This is a test for a larger form i am working on. I want to have a
real time
display of the radio button value when selected. I tried with various event
handlers with varying success. The code below works in mac/win firefox,
other browsers don't handle it at all. I have tried using onclick, and that
buggers it in all browsers.

<script type="text/javascript">
function updateSize()
{if(document.te stform.size[0].checked==true)
document.getEle mentById('displ aySize').innerH TML =
document.testfo rm.size[0].value;

if(document.tes tform.size[1].checked==true)
document.getEle mentById('displ aySize').innerH TML =
document.testfo rm.size[1].value;
}

<form name="testform" >
<input type="radio" id="1" name="size" value="1" onchange="updat eSize();
return false;"><label for="1">1"</label><br />
<input type="radio" id="1.25" name="size" value="1.25"
onchange="updat eSize(); return false;"><label for="1.25">1.25 "</label>
</form>

<p>Size: <span id="displaySize "></span></p>

this site has something similar but has different names for each radio
button
and manually sets the opposite button checked = false. I don't want to do
this because this will cause problems with javascript disabled.
http://webmonkey.wired.com/webmonkey...tw=programming

How should i go about this?

chuck
Sep 11 '05 #1
3 2822
> <script type="text/javascript">
function updateSize()
{if(document.te stform.size[0].checked==true)
document.getEle mentById('displ aySize').innerH TML =
document.testfo rm.size[0].value;

if(document.tes tform.size[1].checked==true)
document.getEle mentById('displ aySize').innerH TML =
document.testfo rm.size[1].value;
} </script> <form name="testform" >
<input type="radio" id="1" name="size" value="1" onchange="updat eSize();
return false;"><label for="1">1"</label><br />
<input type="radio" id="1.25" name="size" value="1.25"
onchange="updat eSize(); return false;"><label for="1.25">1.25 "</label>
</form>

<p>Size: <span id="displaySize "></span></p> chuck

I left out the closing </script> tag in my message but it is in my code.
Sep 11 '05 #2
chuck schrieb:
Hi,
This is a test for a larger form i am working on. I want to have a
real time
display of the radio button value when selected. I tried with various
event
handlers with varying success. The code below works in mac/win firefox,
other browsers don't handle it at all. I have tried using onclick, and
that
buggers it in all browsers.


I tried with onlick too (in a little bit other way) and succeeded in tested
browsers (IE6, FF1.0.6 and Opera8 on win):
<script type="text/javascript">
function updateSize(elem ent) {
document.getEle mentById('displ aySize').innerH TML = element.value;
}
</script>

<form name="testform" >
<input type="radio" id="1" name="size" value="1"
onclick="update Size(this);"><l abel for="1">1"</label><br />
<input type="radio" id="1.25" name="size" value="1.25"
onclick="update Size(this);"><l abel for="1.25">1.25 "</label>
</form>

Beacuse Clicking on a radiobutton allways activates this button (unchecking is
only done by clicking another button in same group), I don't test the
checked-state. Clicking on the label fires (at least on tested browsers) an
onlick-event for the button too.
Sep 11 '05 #3
Martin Kurz wrote:
chuck schrieb:
Hi,
This is a test for a larger form i am working on. I want to have a
real time
display of the radio button value when selected. I tried with various
event
handlers with varying success. The code below works in mac/win firefox,
other browsers don't handle it at all. I have tried using onclick, and
that
buggers it in all browsers.

I tried with onlick too (in a little bit other way) and succeeded in tested
browsers (IE6, FF1.0.6 and Opera8 on win):
<script type="text/javascript">
function updateSize(elem ent) {
document.getEle mentById('displ aySize').innerH TML = element.value;
}
</script>

<form name="testform" >
<input type="radio" id="1" name="size" value="1"


An id must start with a letter. It may contain numbers, but not as the
first character.
onclick="update Size(this);"><l abel for="1">1"</label><br />
<input type="radio" id="1.25" name="size" value="1.25"
onclick="update Size(this);"><l abel for="1.25">1.25 "</label>
</form>
One radio button should always be checked by default.

Beacuse Clicking on a radiobutton allways activates this button (unchecking is
only done by clicking another button in same group), I don't test the
checked-state. Clicking on the label fires (at least on tested browsers) an
onlick-event for the button too.


Clicking on the label is equivalent to clicking on the input in all
browsers that follow the standard.

The label is associated with the input either by making the input part
of the content of the label or by using the label 'for' attribute.
Since IE doesn't implement the first method, the second must be used for
cross-browser consistency.
--
Rob
Sep 12 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

15
2123
by: tabonni | last post by:
I want to check each button groups and save the checked value into a 2 dimensional array. But, it doesn't work. Could anyone tell me what's wrong with my code. My code is as follow: <html> <body> <script language="javascript"> <!-- var temp = new Array(2) var status = new Array();
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!!!
2
3155
by: Jeff | last post by:
I'm trying to create a dynamic form that can have multiple groups of radio buttons (each group has two buttons) with the same name. Essentially, the form allows a user to enter as many names as they want. If they need to add more, they click an "add name" button and the javascript inserts another row of input boxes. Each row should have two radio buttons to indicate sex (M F). When you have multiple text input boxes with the same...
1
3434
by: MickG | last post by:
I am trying to change the value of the variable "hard" according to which radio button is pressed and I am having no joy. Could anyone help me with this, the problematic section is marked with ***********************, I've included all the code incase that isn't where the problem is. Any help would be hugely appreciated. Mick
1
6891
by: kenny8787 | last post by:
Hi, can anyone help here? I have the following code generated from a database, I want to have javascript calculate the costs of the selected items using radio buttons, subtotal the costs and grandtotal the costs ready for the selected items to be inserted back to the database. I did something like this before with Checkboxes, but Radio button have to be named the same to maintain their groupings.
1
2998
by: Bob Sanderson | last post by:
I have a form which uses several radio buttons to enter data. It works fine as far as entering goes, but I can't figure out how to display which button is checked when I view the record. I could do a if-then routine but it seems like there should be an easier way. Any help will be greatly appreciated.
1
1579
by: nowitsoverx | last post by:
I'm just trying to test something out to see if I can get it working but I'm a little stuck. I have two frames. The left one has a menu of radio buttons. I want it so when you click on the radio button it will show the picture in the right frame. When you click on a different radio button I want it to show that picture to the right of the other picture that's already there. When you click another radio button I want it to show that picture...
5
7471
stepterr
by: stepterr | last post by:
I have a form that is built based on a query. Everything is working except when I submit the form the radio buttons are only updating the first row in my database. dcategory and dthumbnail are two radio buttons that I have for each one of the rows in the table. I've tried using a hidden input object for each of the radio button groups to store the values in but clearly I'm having a mental block because I can't get that to work right either. So...
0
9568
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
9399
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
10163
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...
0
9835
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
6649
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
5276
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
5423
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3924
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
3532
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.