Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
 <html>
    <form name="myform" onsubmit="OnSubmitForm();">
       <input type="radio" id = 'first'  name="operation" value="1"
              checked> <label for="alsoFirst"> Answer 1 </label>
       <input type="radio" id = 'second'  name="operation" value="2">
      <label for="alsoSecond">Answer 2</label>
       <p>
       <input type="submit" name="submit" value="save">
       </p>
    </form>
    <script type="text/javascript">
     document.addEventListener('readystatechange', function() {
      // Seems like a GOOD PRACTICE - keeps me from getting type error I was getting
        // http://stackoverflow.com/questions/14207922/javascript-error-null-is-not-an-object
        if (document.readyState === "complete") {
          init();
        }
      });
     function init() {
        console.log ("expect to change -Answer 1- displayed by first button to word junk");
         // this works
        var label = document.getElementsByTagName('label') [0];
        // this does not work
        label.innerHTML = 'junk';
        }
    //http://www.javascript-coder.com/html-form/html-form-action.phtml
    function OnSubmitForm()
    {
      if(document.getElementById('first').checked == true)
        {
        alert ( "You have selected the first answer" );  
        }
      else
        if(document.getElementById('second').checked == true)
            {
            alert ( "You have selected the SECOND answer" );  
            }
      return false;
    }
    /*
    <input type="radio" name="sex" id="male" value="male">
            <label for="male">Male</label>
      </input>
    var input = document.getElementById('male');
    var label = input.getElementsByTagName('label')[0];
    label.innerHTML = 'New Text';
    */
    //http://stackoverflow.com/questions/32292962/javascript-how-to-change-radio-button-label-text
    </script>
    </html>
Output

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
krishcdbrypro
0viewers