Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Jan 2010
    Posts
    16
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Question Can't get code to run past function

    I have a function and then some code within a function, but i can't get the code after the function to run. No matter which function I put first, nothing runs after the function. The function is not recursive and doesn't get caught in an endless loop (code below)
    [CODE]{ if (status.checked)
    {
    check_O2s()
    document.write('what happened here')
    check_O1s()

    }
    }
    [CODE]
    [ICODE]document.write...[ICODE] never gets called
    [CODE]
    function check_O2s()
    {
    for (i=1; i<=20;i++)
    { var idval='O2'.concat(i)
    document.getElementById(idval).checked=true

    }
    return
    }
    [CODE]

    Thanks
    CGG
    Last edited by cgeller100; 08-19-2013 at 12:33 AM. Reason: incomplete information

  • #2
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    4,694
    Thanks
    25
    Thanked 657 Times in 656 Posts
    Lots of things missing here.
    I guess you don't frquent the forums and read users questions and answers? I say that because the mods here will track you down and beat you with a stick for using document.write.

    Anyway javascript has to work on HTML and without it we can't answer your question, but I have added some of my own. See if you can figure out why your code fails:

    Code:
    <html>
    <head>
    <script type="text/javascript">
    function check_me(){
    	var status = document.getElementById("check1").checked;
    	if (status == true){
    		check_O2s();
    		document.write('what happened here');
    		check_O1s();
    	}
    }
    
    function check_O2s(){
    for (i=1; i<=20;i++){
    	var idval='O2'.concat(i);
    	document.getElementById("idval").checked = true;
    }
    return;
    }
    </script>
    </head>
    <body>
    
    <form>
    <input type="checkbox" id="check1" onchange="check_me();">Do you like summer?<br /><br />
    <input type="checkbox" id="idval"">Do check this box!
    </form>
    
    </body>
    </html>
    Evolution - The non-random survival of random variants.

    "If you leave hydrogen alone, for long enough, it begins to think about itself."


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •