Jump to content

[SOLVED] newbie.


phpSensei

Recommended Posts

why is it that after the user gets alerted that the email is empty the page doesnt go to submitpage.htm, but when the name is alerted for being empty, the page loads to submitpage.html

 

<html>
<head>
<script type="text/javascript">
function validate_required(field,alerttxt)
{
with (field)
{
if (value==null||value=="")
  {
  alert(alerttxt);return false
  
  }
else {

return true

}
}
}function validate_form(thisform)
{
with (thisform)
{
if (validate_required(email,"Email must be filled out!")==false)

  {
  email.focus();return false
  
  
  }
  elseif(validate_required(name,"Name must be filled out!")==false)

  {
  name return false
  
  
  }
}
}
</script>
</head><body>
<form action="submitpage.htm"
onsubmit="return validate_form(this)"
method="post">
  <p>Email: 
    <input type="text" name="email" size="30">
    <input type="submit" value="Submit"> 
</p>
  <p>Name 
    <label>
    <input name="name" type="text" id="name">
    </label>
</p>
</form>
</body></html>

Link to comment
Share on other sites

first of all there are some javascript errors on your page, when the name is alerted there is a javascript error and therefore it submits the page I modified your code following is the correct code

 

you just put 'name' instead of name.focus() causing a javascript error

 

<html>
<head>
<script type="text/javascript">
function validate_required(field,alerttxt)
{
with (field)
{
	if (value==null||value=="")
	{
		alert(alerttxt);
		return false;
	}
	else 
	{
		return true;
	}
}
}


function validate_form(thisform)
{
with (thisform)
{
	if (validate_required(email,"Email must be filled out!")==false)
	{
		email.focus();
		return false;
	}
	else if(validate_required(name,"Name must be filled out!")==false)
	{
	    name.focus();
		return false;
	}
}
return true;
}
</script>
</head>
<body>
<form action="submitpage.htm"
onsubmit="return validate_form(this)"
method="post">
  <p>Email: 
	<input type="text" name="email" size="30">
	<input type="submit" value="Submit"> 
</p>
  <p>Name 
	<label>
	<input name="name" type="text" id="name">
	</label>
</p>
</form>
</body>
</html>

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.