plutomed Posted February 15, 2007 Share Posted February 15, 2007 i hate writing javascript but is very useful can anyone tell be what is wrong <script type="text/javascript" language="javascript"> function check() { if(document.getElementById("check").checked=true) { document.getElementById("showemail").value="0" } else if(document.getElementById("check").checked=false) { document.getElementById("showemail").value="1" } } </script> Quote Link to comment https://forums.phpfreaks.com/topic/38684-checkboxes/ Share on other sites More sharing options...
fenway Posted February 15, 2007 Share Posted February 15, 2007 Well, no need to keep getting the DOM element... but you probably mean to use the assignment operator (=), not the comparison operator (==). Quote Link to comment https://forums.phpfreaks.com/topic/38684-checkboxes/#findComment-185804 Share on other sites More sharing options...
plutomed Posted February 15, 2007 Author Share Posted February 15, 2007 oh yes sorry i changed that after but it still doesnt work Quote Link to comment https://forums.phpfreaks.com/topic/38684-checkboxes/#findComment-185807 Share on other sites More sharing options...
fenway Posted February 15, 2007 Share Posted February 15, 2007 Now you have them backwards for the actual .checked comparions. Quote Link to comment https://forums.phpfreaks.com/topic/38684-checkboxes/#findComment-185818 Share on other sites More sharing options...
plutomed Posted February 15, 2007 Author Share Posted February 15, 2007 im sorry you've really confused me can you post the code it should be please Quote Link to comment https://forums.phpfreaks.com/topic/38684-checkboxes/#findComment-185822 Share on other sites More sharing options...
ozfred Posted February 16, 2007 Share Posted February 16, 2007 i hate writing javascript but is very useful can anyone tell be what is wrong <script type="text/javascript" language="javascript"> function check() { if(document.getElementById("check").checked=true) You are assigning the value true, rather than checking it (i.e. use "==" not "="). It is simpler and less error-prone to write: if (document.getElementById("check").checked) Quote Link to comment https://forums.phpfreaks.com/topic/38684-checkboxes/#findComment-185971 Share on other sites More sharing options...
davestewart Posted February 22, 2007 Share Posted February 22, 2007 If you want it really quick: document.getElementById("showemail").value = ! document.getElementById("check").checked or: document.getElementById("showemail").value = document.getElementById("check").checked ? 0 : 1 Quote Link to comment https://forums.phpfreaks.com/topic/38684-checkboxes/#findComment-191341 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.