Jump to content

onsubmit rather than onKeyUp


toolman

Recommended Posts

Hi,

 

I have this code, but I want it to validate when the form is submitted rather than when the user starts to enter text. How would I do that?

 

function checkkey(v) {
if (/\W/.test(v.value)) {
alert("Please enter alphanumerics only");
return false;
}
return true;
}

 

<form  name="snazzyForm" action="index.html" method="POST" onsubmit="return validateForm()" >
<input type="text" name="textfield"   onKeyUp="return checkkey(this)" />
</form>

Link to comment
https://forums.phpfreaks.com/topic/268269-onsubmit-rather-than-onkeyup/
Share on other sites

Thanks.

 

I now have this:

 

function validateForm()
{
var x=document.forms["snazzyForm"]["textfield"].value;
if (x==null || x=="")
  {
  alert("First name must be filled out");
  return false;
  }
  
  if (/\W/.test(v.value)) {
alert("Please enter alphanumerics only");
return false;
}
return true;
}
  
  
}

 

and

 

<form  name="snazzyForm" action="index.html" method="POST" onsubmit="return validateForm()" >
<input type="text" name="textfield"  />
</form>

 

but it doesn't work

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.