Jump to content

Collapsable Divs


ShaolinF

Recommended Posts

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.