display value of radio button

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • poopsy
    New Member
    • Nov 2006
    • 50

    display value of radio button

    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
    Code:
    <html>
     <head>
    <script language="JavaScript">
    
    function display(){
    {
    frm_browser.txt_display.value=frm_broswer.txt_browser.checked.options[frm_browser.txt_browser.selectedIndex].value
    }
    </script>
    </head>
    
    <body>
    <form name="frm_browser">
    Which browser is your favorite<br>
    <input type=radio name="txt_browser" value="explorer" checked Onchange=display()>Microsoft Internet Explorer<br>
    <input type=radio name="txt_browser" value="firefox">Mozilla Firefox
    <br>
    <input type=text name="txt_display" >
    
    </form>
    </html>
    plz help
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    You have to loop over the radio buttons and check which one is checked, e.g.
    [CODE=javascript]var browsers = document.getEle mentsByName("tx t_browser");
    for (i = 0; i < browsers.length ; i++) {
    if (browsers[i].checked) // you've got it here...
    }[/CODE] Your code is trying to use a mixed-up version of something that would work for select drop down elements.

    Comment

    Working...