473,386 Members | 1,706 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

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.testform.size[0].checked==true)
document.getElementById('displaySize').innerHTML =
document.testform.size[0].value;

if(document.testform.size[1].checked==true)
document.getElementById('displaySize').innerHTML =
document.testform.size[1].value;
}

<form name="testform">
<input type="radio" id="1" name="size" value="1" onchange="updateSize();
return false;"><label for="1">1"</label><br />
<input type="radio" id="1.25" name="size" value="1.25"
onchange="updateSize(); 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 2795
> <script type="text/javascript">
function updateSize()
{if(document.testform.size[0].checked==true)
document.getElementById('displaySize').innerHTML =
document.testform.size[0].value;

if(document.testform.size[1].checked==true)
document.getElementById('displaySize').innerHTML =
document.testform.size[1].value;
} </script> <form name="testform">
<input type="radio" id="1" name="size" value="1" onchange="updateSize();
return false;"><label for="1">1"</label><br />
<input type="radio" id="1.25" name="size" value="1.25"
onchange="updateSize(); 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(element) {
document.getElementById('displaySize').innerHTML = element.value;
}
</script>

<form name="testform">
<input type="radio" id="1" name="size" value="1"
onclick="updateSize(this);"><label for="1">1"</label><br />
<input type="radio" id="1.25" name="size" value="1.25"
onclick="updateSize(this);"><label 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(element) {
document.getElementById('displaySize').innerHTML = 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="updateSize(this);"><label for="1">1"</label><br />
<input type="radio" id="1.25" name="size" value="1.25"
onclick="updateSize(this);"><label 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
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>...
1
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...
10
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...
2
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...
1
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...
1
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...
1
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...
1
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...
5
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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...

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.