473,407 Members | 2,598 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,407 software developers and data experts.

display value of radio button

50
hi all, i' hav this question where i have a radio button and select one of 2 choices, whichever i select hav to display in the input box but it doesnt work
here is the code
Expand|Select|Wrap|Line Numbers
  1. <html>
  2.  <head>
  3. <script language="JavaScript">
  4.  
  5. function display(){
  6. {
  7. frm_browser.txt_display.value=frm_broswer.txt_browser.checked.options[frm_browser.txt_browser.selectedIndex].value
  8. }
  9. </script>
  10. </head>
  11.  
  12. <body>
  13. <form name="frm_browser">
  14. Which browser is your favorite<br>
  15. <input type=radio name="txt_browser" value="explorer" checked Onchange=display()>Microsoft Internet Explorer<br>
  16. <input type=radio name="txt_browser" value="firefox">Mozilla Firefox
  17. <br>
  18. <input type=text name="txt_display" >
  19.  
  20. </form>
  21. </html>
  22.  
plz help
Oct 29 '07 #1
1 2300
acoder
16,027 Expert Mod 8TB
You have to loop over the radio buttons and check which one is checked, e.g.
Expand|Select|Wrap|Line Numbers
  1. var browsers = document.getElementsByName("txt_browser");
  2. for (i = 0; i < browsers.length; i++) {
  3.   if (browsers[i].checked) // you've got it here...
  4. }
Your code is trying to use a mixed-up version of something that would work for select drop down elements.
Oct 30 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

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: jason | last post by:
The following (likely far from imperfect code), reports a value of NaN in the j4 display. I suppose the problem is I am not really passing the "checked" value of the radio button via .value ......
3
by: chuck | last post by:
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...
1
by: PeeZee | last post by:
I am having some trouble getting this done. I am able to get the value to display on a seperate page but not on the same page in the same form. I would like to display to set value of the radio...
2
by: slitchfield | last post by:
Sorry if this is real beginner's stuff, but I'm an old-school HTML guy and this is all another world to me. Is there an easy way to get the user to specify a number from 1 to 5 (in a pick list...
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...
11
by: nickyeng | last post by:
I have a html file contains a form asking user to select a choice and press enter to pass the data to server. In server there, i have a cgi script(C language) that accepts the input from browser...
3
by: rajarya | last post by:
Hi, I m designing a HTML page(index.html),here i have 2 frames,by defult both frames have index1.html and index2.html as their source . in first frame(index.html) ,i have some redio buttons,and a...
1
by: sourcie | last post by:
I am changing an existing quiz found on "JavaScriptKit.com Multiple Choice Quiz" I have an image. Instead of using the radio buttons with the normal true/false question, I want to place two...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
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...
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
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...
0
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,...

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.