zero-perfoliate
zero-perfoliate

Author Topic: script problem  (Read 2161 times)

Offline kazam

  • PHP Workers
  • **
  • Posts: 9
  • Karma: +0/-0
script problem
« on: March 31, 2010, 09:35:32 PM »
I was wondering whats wrong with my script because its not working? I had just the email part first and that was working then I added the other stuff to check the rest and now none of it works.

<script type="text/javascript">
function checkForm()
{
var cname, cmessage,
with(window.document.contact)
{
cname = name;
cmessage = message;
}
if(cname.value == '')
{
alert('Please enter your name!');
cname.focus();
return false;
}
if (cmessage.value == '')
{
alert('Please enter your first name!');
cmessage.focus();
return false;
}
}
<!--
function emailcheck(cur)
{
var string1=cur.email.value
if (string1.indexOf("@")==-1)
{
alert("Please input a valid email address!")
return false
}
}
//-->
  </script>

Offline RoseKnight

  • PHP Help Guru's
  • ****
  • Posts: 52
  • Karma: +0/-0
Re: script problem
« Reply #1 on: April 01, 2010, 06:15:59 PM »
you commented out your email check and alert functions.

hotnoob

  • Guest
Re: script problem
« Reply #2 on: April 02, 2010, 01:09:31 AM »
You need to include both of those functions for the check...

So, your form tag should be like
<form action="blah.php" method=post onSubmit="return checkForm();">

Than your script
Code: [Select]
function checkForm()
{
var errors = 0;
var errorMsg = "";
with(window.document.contact)
{
cname = name;
cmessage = message;
}
if(cname.value == '')
{
errorMsg += 'Please enter your name!\n';
errors++;
cname.focus();
}
if (cmessage.value == '')
{
errorMsg += 'Please enter your first\n';
errors++;
cmessage.focus();
}
/*email check I donno what you have for cur, but make sure you change it or this wont work*/
if (cur.email.value.indexOf("@")==-1)
{
errorMsg  += "Please input a valid email address!\n";
errors++;
}
if(errors < 0)
{
alert(errors+"error(s):\n"+errorMsg);
return false;
}
else
{
return true;
}


}



Offline josh.legogeek

  • PHP Workers
  • **
  • Posts: 5
  • Karma: +0/-0
Re: script problem
« Reply #3 on: May 18, 2010, 05:49:11 PM »
For the email check you can use
Code: [Select]
var regex = /\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b/i
if (regex.test(cur.email.value))
{
   ...
}

Offline siddle63

  • New PHP Members
  • Posts: 1
  • Karma: +0/-0
Re: script problem
« Reply #4 on: March 16, 2011, 09:01:17 PM »
A playscript on this author may be engaged, or it may love obstructed responding. You can grab the script now, or you can speak to see if the playscript module thoroughgoing.