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
Expand|Select|Wrap|Line Numbers
- <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>
Xoinki