Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

"Return" help

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
Hi,

I'm new with javascript just for the mentioning. Anyway, I made a custom code, but can't figure out why the form continues to submit even when the argument is FALSE. I've just about had it with this onSubmit stuff. P.S. if you could copy the code and reply it with corrections, it would be helpful.

Thanks, here is the new custom script:
Code:
<html>

<head>
<meta name=&quot;GENERATOR&quot; content=&quot;Microsoft FrontPage 5.0&quot;>
<meta name=&quot;ProgId&quot; content=&quot;FrontPage.Editor.Document&quot;>
<meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=windows-1252&quot;>
<title>Name</title>
</head>

<body>
<SCRIPT LANGUAGE=&quot;JavaScript&quot;>
function runAll() {

emailCheck(document.info.email.value);
}

function emailCheck (emailStr) {
var checkTLD=0;
var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;
var emailPat=/^(.+)@(.+)$/;
var specialChars=&quot;\\(\\)><@,;:\\\\\\\&quot;\\.\\[\\]&quot;;
var validChars=&quot;\[^\\s&quot; + specialChars + &quot;\]&quot;;
var quotedUser=&quot;(\&quot;[^\&quot;]*\&quot;)&quot;;
var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
var atom=validChars + '+';
var word=&quot;(&quot; + atom + &quot;|&quot; + quotedUser + &quot;)&quot;;
var userPat=new RegExp(&quot;^&quot; + word + &quot;(\\.&quot; + word + &quot;)*$&quot;);
var domainPat=new RegExp(&quot;^&quot; + atom + &quot;(\\.&quot; + atom +&quot;)*$&quot;);
var matchArray=emailStr.match(emailPat);
if (matchArray==null) {
alert(&quot;The Email Address Is Invalid&quot;);
return false;
}
var user=matchArray[1];
var domain=matchArray[2];
for (i=0; i<user.length; i++) {
if (user.charCodeAt(i)>127) {
alert(&quot;The Username Contains Invalid Characters.&quot;);
return false;
   }
}
for (i=0; i<domain.length; i++) {
if (domain.charCodeAt(i)>127) {
alert(&quot;Ths Domain Name Contains Invalid Characters.&quot;);
return false;
   }
}
if (user.match(userPat)==null) {
alert(&quot;The Username Is Invalid.&quot;);
return false;
}
var IPArray=domain.match(ipDomainPat);
if (IPArray!=null) {
for (var i=1;i<=4;i++) {
if (IPArray[i]>255) {
alert(&quot;The Destination IP Address Is Invalid.&quot;);
return false;
   }
}
return true;
}
var atomPat=new RegExp(&quot;^&quot; + atom + &quot;$&quot;);
var domArr=domain.split(&quot;.&quot;);
var len=domArr.length;
for (i=0;i<len;i++) {
if (domArr[i].search(atomPat)==-1) {
alert(&quot;The Domain Name Is Invalid.&quot;);
return false;
   }
}
if (checkTLD && domArr[domArr.length-1].length!=2 && 
domArr[domArr.length-1].search(knownDomsPat)==-1) {
alert(&quot;The Domain Name Extension Is Invalid&quot;);
return false;
}
if (len<2) {
alert(&quot;The Address Is Missing A Hostname.&quot;);
   return false;
   }

else 
   {if ( document.info.name.value == &quot;&quot; ) 
{ 
alert ( &quot;Your Name Is Missing.&quot; ); 
return false; 

return true;
     }
}
}
</script>
<form name=info method=&quot;POST&quot; action=&quot;form.cgi&quot; onSubmit=&quot;return runAll()&quot;>
<p>Name:<br>
<input type=&quot;text&quot; name=&quot;name&quot; size=&quot;20&quot;>
<p>Email:<br>
<input type=&quot;text&quot; name=&quot;email&quot; size=&quot;20&quot;>
<input type=&quot;submit&quot; value=&quot;Submit&quot; name=&quot;B1&quot;></form>

</body>
</html>
 
change the function to look like this :

function runAll() {

return emailCheck(document.info.email.value);
}
 
hi!

the problem with using the submit type that it will submit ur form no matter what ull do or check after its been clicked there for i added a function to ur code and some minor changes on ur html:

<html>

<head>
<meta name=&quot;GENERATOR&quot; content=&quot;Microsoft FrontPage 5.0&quot;>
<meta name=&quot;ProgId&quot; content=&quot;FrontPage.Editor.Document&quot;>
<meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=windows-1252&quot;>
<title>Name</title>
</head>

<body>
<SCRIPT LANGUAGE=&quot;JavaScript&quot;>

function emailCheck (emailStr) {
var checkTLD=0;
var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;
var emailPat=/^(.+)@(.+)$/;
var specialChars=&quot;\\(\\)><@,;:\\\\\\\&quot;\\.\\[\\]&quot;;
var validChars=&quot;\[^\\s&quot; + specialChars + &quot;\]&quot;;
var quotedUser=&quot;(\&quot;[^\&quot;]*\&quot;)&quot;;
var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
var atom=validChars + '+';
var word=&quot;(&quot; + atom + &quot;|&quot; + quotedUser + &quot;)&quot;;
var userPat=new RegExp(&quot;^&quot; + word + &quot;(\\.&quot; + word + &quot;)*$&quot;);
var domainPat=new RegExp(&quot;^&quot; + atom + &quot;(\\.&quot; + atom +&quot;)*$&quot;);
var matchArray=emailStr.match(emailPat);
if (matchArray==null) {
alert(&quot;The Email Address Is Invalid&quot;);
return false;
}
var user=matchArray[1];
var domain=matchArray[2];
for (i=0; i<user.length; i++) {
if (user.charCodeAt(i)>127) {
alert(&quot;The Username Contains Invalid Characters.&quot;);
return false;
}
}
for (i=0; i<domain.length; i++) {
if (domain.charCodeAt(i)>127) {
alert(&quot;Ths Domain Name Contains Invalid Characters.&quot;);
return false;
}
}
if (user.match(userPat)==null) {
alert(&quot;The Username Is Invalid.&quot;);
return false;
}
var IPArray=domain.match(ipDomainPat);
if (IPArray!=null) {
for (var i=1;i<=4;i++) {
if (IPArray>255) {
alert(&quot;The Destination IP Address Is Invalid.&quot;);
return false;
}
}
return true;
}
var atomPat=new RegExp(&quot;^&quot; + atom + &quot;$&quot;);
var domArr=domain.split(&quot;.&quot;);
var len=domArr.length;
for (i=0;i<len;i++) {
if (domArr.search(atomPat)==-1) {
alert(&quot;The Domain Name Is Invalid.&quot;);
return false;
}
}
if (checkTLD && domArr[domArr.length-1].length!=2 &&
domArr[domArr.length-1].search(knownDomsPat)==-1) {
alert(&quot;The Domain Name Extension Is Invalid&quot;);
return false;
}
if (len<2) {
alert(&quot;The Address Is Missing A Hostname.&quot;);
return false;
}

else
{if ( document.info.name.value == &quot;&quot; )
{
alert ( &quot;Your Name Is Missing.&quot; );
return false;

return true;
}
}
}

function submitChk() {
if (emailCheck(document.info.email.value))
{
document.info.submit();
return;
}
//if false then do something.....

}

</script>
<form name=info method=&quot;POST&quot; action=&quot;form.cgi&quot; >
<p>Name:<br>
<input type=&quot;text&quot; name=&quot;name&quot; size=&quot;20&quot;>
<p>Email:<br>
<input type=&quot;text&quot; name=&quot;email&quot; size=&quot;20&quot;>
<input type=&quot;button&quot; value=&quot;Submit&quot; onClick=&quot;submitChk()&quot; name=&quot;B1&quot;></form>

</body>
</html>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top