ShaolinF Posted October 14, 2007 Share Posted October 14, 2007 Hi guys, Im trying to use div tags to check my form fields. The problem is when I submit it doesn't do anything. See code: <form action="continue.php" name="signup" method="post" onsubmit="return toggleDiv(this);"> <p><label for="name">Your Name:</label><br /> <input type="text" name="name" size="26" /><br /> <br /> <label for="contact">Your Contact No:</label><br /> <input type="text" name="contact" size="26" /><br /> <br /> <label for="email">Your Email:</label><br /> <input type="text" name="email" size="26" /><br /> <br /> <input type="radio" name="sex" value="Male" class="radioStyle" /> Male <input type="radio" name="sex" value="Female" class="radioStyle" /> Female<br /> <br /> <input type="reset" class="altButtonFormat" /> <input type="submit" value="Continue >>" class="altButtonFormat" /></p> </form> <script language="javascript"> function toggleDiv(signup){ if(signup.name.value == "") { document.getElementById(mydiv).style.display = 'block'; return false; } } </script> <div id="mydiv" style="display:none"><h3>This is a test!<br>Can you see me?</h3></div> Link to comment https://forums.phpfreaks.com/topic/73186-collapsable-divs/ Share on other sites More sharing options...
mainewoods Posted October 14, 2007 Share Posted October 14, 2007 function toggleDiv(signup){ if(signup.name.value == "") { document.getElementById(mydiv).style.display = 'block'; return false; } } --the 'mydiv' above must have quotes around it or javascript will interpret it as a variable that is undefined. Use: document.getElementById('mydiv').style.display = 'block'; Link to comment https://forums.phpfreaks.com/topic/73186-collapsable-divs/#findComment-369540 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.