Jump to content

Recommended Posts

Please help me to figure out why this form isnt working at all..

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Registration Form</title>
</head>
<body>
<script type='text/javascript'>
function formValidator(){
var name = document.getElementById('name');
var email = document.getElementById('email');
var password = document.getElementById('password');

if(notEmpty(name, "Please enter only letters for your First name")){
	if(lr(password, 6, 12)){
		if(notEmpty(email, "Please enter only letters for your Last Name")){

			return true;																							
		}
	}
}
return false;
	}

function notEmpty(elem, helperMsg){
if(elem.value.length == 0){
	alert(helperMsg);
	elem.focus();
	return false;
}
return true;
}


function lr(elem, min, max){
var uInput = elem.value;
if(uInput.length >= min && uInput.length <= max){
	return true;
}else{
	alert("Please enter between " +min+ " and " +max+ " characters");
	elem.focus();
	return false;
}
}

</SCRIPT>

<form action='' onsubmit='return formValidator()' name='myform' method='get' >
<table width="425" height="166" border="0">
  <tr>
    <td colspan="2"><h1>Registration Form </h1></td>
  </tr>
  <tr>
    <td width="122">Name</td>
    <td width="287">
      <input name="name" type="text" id="name" maxlength="15" />
   
    </td>
  </tr>
  <tr>
    <td>Email Address </td>
    <td><input name="email" type="text" id="email" maxlength="15" /></td>
  </tr>
  <tr>
    <td>Password</td>
    <td><input name="password" type="password" id="password" /></td>
  </tr>
  <tr>
    <td> </td>
    <td><input type="button" name="Submit" value="Submit" onmouseover=" document.myform.submit()" />
      <input type="reset" name="reset" value="Reset" /></td>
  </tr>
</table>
</form>
</body>
</html>

Link to comment
https://forums.phpfreaks.com/topic/182388-javascript-help/
Share on other sites

A description about what it exactly is that isn't working and when along with what errors you might receive would be helpful. Just dumping your complete html page and expecting someone to figure out what your problem is not likely going to get you help any time soon.

Link to comment
https://forums.phpfreaks.com/topic/182388-javascript-help/#findComment-962441
Share on other sites

Even though this is clearly homework, which is against the rules to post, I'll give you a nudge in the right direction.

 

Your logic isn't very efficient.  It makes far more sense to tie the validation function to the input's onmouseover event, and leave the actual form submission to clicking the button instead of blindly sticking event handlers in your code.  In fact, if you re-read the question in your assignment, that's exactly what it's telling you to do.

Link to comment
https://forums.phpfreaks.com/topic/182388-javascript-help/#findComment-963277
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.