rv20 Posted May 23, 2009 Share Posted May 23, 2009 I am trying to work out if one of my checkboxes is checked or not, the CB is inside a form called "myform" if that makes a difference and the checkboxes ID = "check_terms" - oh and the function name is also check_terms so i didn't make a mistake. so i tried, function check_terms(){ if (document.check_terms.checked == false){ alert('test'); } } didn't seem to work after clickig submit, i then tried, function check_terms(){ if (document.getElementById('check_terms').checked == false){ alert('test'); } } You may have to add a forms['myform'] or something in there somwhere i couldn't get it, Should you use document.getelementbyID...... or just document."elementname"..... or is it window.document.elementname..... confused! Quote Link to comment Share on other sites More sharing options...
Axeia Posted May 23, 2009 Share Posted May 23, 2009 Second version should work (if you got a <input type='checkbox' id='check_terms' /> on the same page) document.getElementById( 'id' ); is correct. Think the first version indeed needs a form reference in there somewhere. Quote Link to comment Share on other sites More sharing options...
Psycho Posted May 23, 2009 Share Posted May 23, 2009 You should never use the same name for anything even if they are structurally different objects (e.g. a function and a field name). It will only cause confusion even if it does work. In any event, the second block of code should work - at least it did for me when I tested it with a field and function named the same (both IE & FF). Quote Link to comment Share on other sites More sharing options...
.josh Posted May 23, 2009 Share Posted May 23, 2009 so where's the code that actually calls your function? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.