leijae Posted July 6, 2011 Share Posted July 6, 2011 I can get it work when I click a radio. // this is my javascript function hidey(val) { if(val == 'on' || val === true) { document.getElementById('a1').checked = true; document.getElementById('toshow').style.display = 'block'; document.getElementById('tohide').style.display = 'none'; } else if(val == 'off' || val === false) { document.getElementById('a2').checked = true; document.getElementById('toshow').style.display = 'none'; } } //this is my html <form action=" " method="post"> This is on <input id="a1" name="kind" type="radio" value="on" checked="checked" onclick="hidey(this.checked);" /><br /> This is off <input id="a2" name="kind" type="radio" value="on" checked="checked" onclick="hidey(this.checked);" /> that works fine, but I can't find anywhere on how to run a function like "hidey" when a button is clicked. Here's my attempt: //this is my javascript function hidey(val) { if(val == 'on' || val === true) { document.getElementById('a1').checked = true; document.getElementById('toshow').style.display = 'block'; document.getElementById('tohide').style.display = 'none'; } else if(val == 'off' || val === false) { document.getElementById('a2').checked = true; document.getElementById('toshow').style.display = 'none'; } } //this is my html <input class="button" type="button" value="Continue" onclick="hidey(this.clicked);"> i understand that the value isn't on, but that's why i put "true". because when it's clicked, it's true, right? Quote Link to comment https://forums.phpfreaks.com/topic/241254-hiding-a-div-on-button-click-stuck/ Share on other sites More sharing options...
leijae Posted July 6, 2011 Author Share Posted July 6, 2011 I get the error: hidey(); must be inside loop Quote Link to comment https://forums.phpfreaks.com/topic/241254-hiding-a-div-on-button-click-stuck/#findComment-1239276 Share on other sites More sharing options...
leijae Posted July 7, 2011 Author Share Posted July 7, 2011 bump for a cool guy? Quote Link to comment https://forums.phpfreaks.com/topic/241254-hiding-a-div-on-button-click-stuck/#findComment-1239735 Share on other sites More sharing options...
Zane Posted July 7, 2011 Share Posted July 7, 2011 What exactly are you trying to do? Hide the checkbox? Quote Link to comment https://forums.phpfreaks.com/topic/241254-hiding-a-div-on-button-click-stuck/#findComment-1239796 Share on other sites More sharing options...
leijae Posted July 7, 2011 Author Share Posted July 7, 2011 I'm trying to run the function "hidey" when I click the button, but I want the exact same results as when I click the radio. It hides the div "tohide" and shows the div "toshow" Quote Link to comment https://forums.phpfreaks.com/topic/241254-hiding-a-div-on-button-click-stuck/#findComment-1239807 Share on other sites More sharing options...
Zane Posted July 7, 2011 Share Posted July 7, 2011 onclick should be onClick EDIT: nevermind.. i don't think HTML attributes are case-sensitive. Quote Link to comment https://forums.phpfreaks.com/topic/241254-hiding-a-div-on-button-click-stuck/#findComment-1239812 Share on other sites More sharing options...
Zane Posted July 7, 2011 Share Posted July 7, 2011 you're passing an attribute of this that doesn't exist in this element. You made need to alter your javascript IF statement to include the word "Continue".. you'll also have to change what you're passing to hidey. like this Quote Link to comment https://forums.phpfreaks.com/topic/241254-hiding-a-div-on-button-click-stuck/#findComment-1239816 Share on other sites More sharing options...
leijae Posted July 7, 2011 Author Share Posted July 7, 2011 that worked! great! thanks Zanus! [sOLVED] Quote Link to comment https://forums.phpfreaks.com/topic/241254-hiding-a-div-on-button-click-stuck/#findComment-1239835 Share on other sites More sharing options...
Adam Posted July 7, 2011 Share Posted July 7, 2011 onclick should be onClick EDIT: nevermind.. i don't think HTML attributes are case-sensitive. Only XHTML is case-sensitive. Quote Link to comment https://forums.phpfreaks.com/topic/241254-hiding-a-div-on-button-click-stuck/#findComment-1239842 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.