SitePoint Sponsor |
|
User Tag List
Results 1 to 5 of 5
-
Jul 29, 2003, 01:01 #1
- Join Date
- Apr 2003
- Location
- Anywhere
- Posts
- 46
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
problem with radio button and javascript
I cannot see the value of the <input type="radio".....
through the javascript code
-
Jul 29, 2003, 01:56 #2
- Join Date
- Jul 2003
- Location
- Moncton, New Brunswick, Canada
- Posts
- 247
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Hi,
Since you didn't post your code I have no way of knowing what your doing wrong, but try this and see if it sheds any light on your problem.
Code:<html> <head> <script type="text/javascript"> function getRadioVals(el) { var str = '', i = 0; for(i; i < el.length; i++) { str += 'Value of radio '+i+': ' + '"' + el[i].value + '"' + '\n\t checked = ' + el[i].checked + '\n'; } alert(str); } </script> </head> <body> <form name="f"> <input type="radio" name="radios" value="val0" /> 1<br /> <input type="radio" name="radios" value="val1" checked="checked" /> 2<br /> <input type="radio" name="radios" value="val2" /> 3<br /> <input type="radio" name="radios" value="val3" /> 4<br /> </form> <a href="#" onclick="getRadioVals(document.f.radios); return false;">get Radio Properties</a> </body> </html>
-
Jul 29, 2003, 03:04 #3
- Join Date
- Apr 2003
- Location
- Anywhere
- Posts
- 46
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Code:<script> function check() { var radioValue=document.formName.radios.value; alert(radioValue); } </script> ..... .... <input type="radio" name="radios" value="1">
-
Jul 29, 2003, 03:13 #4
- Join Date
- Jul 2003
- Location
- Moncton, New Brunswick, Canada
- Posts
- 247
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Originally Posted by dominant
That's why in my example code I looped through my 4 radio buttons to show you that radio button are indeed arrays. Did you try the code?
e.g:
Code:<input type="radio" name="radios" value="1"> <input type="radio" name="radios" value="2">
document.formName.radios[1].value, which is 2!
Arrays start at index 0, so your first radio button value is always referenced as document.formName.radioButtonGroupName[0].value, or in the case of the above code:
document.formName.radios[0].value
Some links for you:
http://www.devguru.com/Technologies/...ref/radio.html
http://devedge.netscape.com/library/...nce/radio.html
http://tech.irt.org/articles/js216/index11.htm
http://www.jennifermadden.com/162/ex...loopRadio.html
-xDevLast edited by xDev; Jul 29, 2003 at 03:35.
-
Jul 29, 2003, 04:31 #5
- Join Date
- Apr 2003
- Location
- Anywhere
- Posts
- 46
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Thank you for your help!
Bookmarks