Identify which radio button is selected

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • xoinki
    New Member
    • Apr 2007
    • 110

    Identify which radio button is selected

    hi all,
    I am just trying to identify which radio button is selected in JS.
    although the code in totality does not make any sense since this is just a sample. it is not able to identify the 's' name as child element of the form.
    here is the code
    Code:
    <html>
    <head>
    <script language = "javascript">
    window.onload = function()
    {
    	var form = document.createElement("form");
    	form.name = "myForm";
    	form.innerHTML = "<input type = radio name = 's' value = 'Log'>Log</input><input type = 'radio' name = 's' value = 'General Log'>General Log</input><input type = 'radio' name = 's' value = 'Sniffer'>Sniffer</input>";
    	var id = document.getElementById('initpage');
    	id.appendChild(form);
    	var myForm = document.getElementsByName("myForm");
    	debugger;
            var length = myForm[0].s.length;
    	alert(length);
    	for(i =0; i< length; i++)
    	{
    		if (myForm[0].radios[i].checked) 
    		{
    			user_input = myForm[0].radios[i].value;	
    		}
    	}
    }
    </script>
    </head>
    <body>
    <div id="initpage">
    </div>
    </body>
    
    </html>
    thanks and regards,
    Xoinki
  • xoinki
    New Member
    • Apr 2007
    • 110

    #2
    hi,
    dont bother to reply..
    I found the issue..
    its a silly mistake in code..
    thnx and regards,
    Xoinki

    Comment

    • acoder
      Recognized Expert MVP
      • Nov 2006
      • 16032

      #3
      Changed the thread title to better describe the problem.

      I assume the problem was "radios" should be "s".

      Comment

      Working...