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
https://forums.phpfreaks.com/topic/77559-solved-newbie/
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
https://forums.phpfreaks.com/topic/77559-solved-newbie/#findComment-392731
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.