ralphuk100
asked on
form validation script....
I need to validate this form...but before its submitted it needs to check in the SQL Server DB that the username they want is not already taken, then it needs to check they have entered their email twice, and that they match, and the same for password, it also needs to validate the email for a @ and . and needs to make sure all fields have something entered (apart from non-required ones) as well as make sure the right amount of characters have been entered. After the form I have put the functions I already have. Thanks:
<div class="registrationForm" name="registrationForm">
<form name="REGISTRATION" method="POST" action="#" ID="Form1">
<div class="accountType">
<table width="452" border="0" cellpadding="2" cellspacing="0" class="registrationForm" ID="Table2">
 <tr>
  <td colspan="3" class="critical"><b>All fields in RED are required</b></td>
 </tr> Â
 <tr>
  <td colspan="3" class="sectionName">Choose Account</td>
 </tr>
 <tr>
  <td colspan="3"><hr class="registrationForm">< /td>
 </tr> Â
 <tr>
  <td class="critical">Account Type</td>
  <td class="field">
           <b>FREE ACCESS UNTIL - (date here)</b>
  </td>
  <td><a href="#" class="help" onmouseover="showtip(this, event,'CHO OSE YOUR TYPE OF ACCOUNT. TRIALS ARE FOR A PERIOD OF FIVE DAYS')" onmouseout="hidetip()">?</ a></td>  Â
 </tr>
</table>
</div>
<br>
<div class="address">
<table width="452" border="0" cellpadding="2" cellspacing="0" class="registrationForm" ID="Table1">
 <tr>
  <td colspan="3" class="sectionName">Person al Details and Address</td>
 </tr>
 <tr>
  <td colspan="3"><hr class="registrationForm">< /td>
 </tr> Â
 <tr>
  <td class="critical">Preferred User Name</td>
  <td class="field"><input type="text" class="registrationFormADD RESS" name="userName" ID="Text1">
  </td>
  <td><a href="#" class="help" onmouseover="showtip(this, event,'USE D TO LOG INTO FFS')" onmouseout="hidetip()">?</ a></td>  Â
 </tr>
 <tr>
  <td class="critical"></td>
  <td class="characterCount">
  <script>
      displaylimit("document.REG ISTRATION. userName", 20)
      </script>
  </td>
  <td></td>  Â
 </tr>
 <tr>
  <td class="critical">Your Email Address</td>
  <td class="field"><input type="text" class="registrationFormADD RESS" name="userEmailOne" ID="Text2"></td>
      <td><a href="#" class="help" onmouseover="showtip(this, event,'MUS T BE VALID TO ACTIVATE YOUR ACCOUNT AND MATCH THE CONFIRMING EMAIL')" onmouseout="hidetip()">?</ a></td> Â
 </tr>
 <tr>
  <td class="critical">Confirm Email</td>
  <td class="field"><input type="text" class="registrationFormADD RESS" name="userEmailTwo" ID="Text3"></td>
      <td><a href="#" class="help" onmouseover="showtip(this, event,'MUS T MATCH YOUR EMAIL ADDRESS')" onmouseout="hidetip()">?</ a></td>   Â
 </tr> Â
 <tr>
  <td class="critical">Password< /td>
  <td class="field"><input type="password" class="registrationFormADD RESS" name="" ID="Password1"></td>
      <td><a href="#" class="help" onmouseover="showtip(this, event,'CHO OSE A PASSWORD. THIS IS NOT CASE SENSITIVE. MUST BE CONFIRMED BELOW')" onmouseout="hidetip()">?</ a></td>   Â
 </tr>
 <tr>
  <td class="critical">Confirm Password</td>
  <td class="field"><input type="password" class="registrationFormADD RESS" name="" ID="Text4"></td>
      <td><a href="#" class="help" onmouseover="showtip(this, event,'CON FIRM YOUR PASSWORD')" onmouseout="hidetip()">?</ a></td>   Â
 </tr>
 <tr>
  <td class="field">Street Address</td>
  <td class="field"><input type="text" class="registrationFormADD RESS" name="" ID="Text5"></td>
      <td><a href="#" class="help" onmouseover="showtip(this, event,'HOU SE NUMBER AND STREET')" onmouseout="hidetip()">?</ a></td>   Â
 </tr>
 <tr>
  <td>Village</td>
  <td class="field"><input type="text" class="registrationFormADD RESS" name="" ID="Text6"></td>
      <td><a href="#" class="help" onmouseover="showtip(this, event,'YOU R VILLAGE, IF APPLICABLE')" onmouseout="hidetip()">?</ a></td>   Â
 </tr>
 <tr>
  <td>Town</td>
  <td class="field"><input type="text" class="registrationFormADD RESS" name="" ID="Text7"></td>
      <td><a href="#" class="help" onmouseover="showtip(this, event,'YOU R TOWN, IF APPLICABLE')" onmouseout="hidetip()">?</ a></td>   Â
 </tr>
 <tr>
  <td class="critical">City</td>
  <td class="field"><input type="text" class="registrationFormADD RESS" name="" ID="Text8"></td>
      <td><a href="#" class="help" onmouseover="showtip(this, event,'YOU R CITY')" onmouseout="hidetip()">?</ a></td>   Â
 </tr>
 <tr>
  <td class="field">County</td>
  <td class="field"><input type="text" class="registrationFormADD RESS" name="" ID="Text9"></td>
      <td><a href="#" class="help" onmouseover="showtip(this, event,'YOU R COUNTY')" onmouseout="hidetip()">?</ a></td>   Â
 </tr>
 <tr>
  <td class="field">Postcode</td >
  <td class="field"><input type="text" class="registrationFormADD RESS" name="postCode" ID="Text10"></td>
      <td><a href="#" class="help" onmouseover="showtip(this, event,'YOU R POSTCODE')" onmouseout="hidetip()">?</ a></td>   Â
 </tr>
 <tr>
  <td class="critical">Country</ td>
  <td class="field"><input type="text" class="registrationFormADD RESS" name="" ID="Text11"></td>
      <td><a href="#" class="help" onmouseover="showtip(this, event,'YOU R COUNTRY')" onmouseout="hidetip()">?</ a></td>   Â
 </tr>
 <tr>
  <td>Home Telephone</td>
  <td class="field"><input type="text" class="registrationFormADD RESS" name="homePhone" ID="Text12"></td>
      <td><a href="#" class="help" onmouseover="showtip(this, event,'HOM E TELEPHONE NUMBER')" onmouseout="hidetip()">?</ a></td>   Â
 </tr> Â
 <tr>
  <td>Mobile Telephone</td>
  <td class="field"><input type="text" class="registrationFormADD RESS" name="mobilePhone" ID="Text13"></td>
      <td><a href="#" class="help" onmouseover="showtip(this, event,'WE AIM TO LAUNCH A MEMBERS SMS SERVICE IN THE SECOND QUARTER OF 2003. YOUR MOBILE NUMBER WILL BE REQUIRED TO USE THIS')" onmouseout="hidetip()">?</ a></td>   Â
 </tr>
 <tr>
  <td colspan="2" width="400"><b>You must accept the terms and conditions</b><input type="checkbox" name="TOS" ID="Checkbox1"></td>
      <td><a href="#" class="help" onmouseover="showtip(this, event,'YOU MUST ACCEPT THE TERMS AND CONDITIONS OF SERVICE IN ORDER TO SUBMIT THIS FORM')" onmouseout="hidetip()">?</ a></td>   Â
 </tr>
 <tr>
  <td colspan="2" width="400"><INPUT type="submit" value="Submit" ID="Submit1" NAME="Submit1" onClick="checkEmail();"></ td>
      <td><a href="#" class="help"></a></td>   Â
 </tr> Â
</form>
Â
</table>
</div>
SCRIPT FOR PAYMENT DETAILS:
var isIE=document.all?true:fal se;
var isDOM=document.getElementB yId?true:f alse;
var isNS4=document.layers?true :false;
/* _w : which ID (1) or (2) */
/* _h : (h)ide or (s)how */
function toggleT(_w,_h) {
 if (isDOM)
 {
  if (_h=='s') document.getElementById(_w ).style.vi sibility=' visible';
  if (_h=='h') document.getElementById(_w ).style.vi sibility=' hidden';
 }
 else if (isIE) {
  if (_h=='s') eval("document.all."+_w+". style.visi bility='vi sible';");
  if (_h=='h') eval("document.all."+_w+". style.disp lay='inlin e';");
 }
 else if(isNS4)
 {
  if (_h=='s') eval("document.layers['"+_ w+"'].visi bility='sh ow';");
  if (_h=='h') eval("document.layers['"+_ w+"'].visi bility='hi de';");
 }
}
SCRIPT TO COUNT REMAINING CHARACTERS:
var ns6=document.getElementByI d&&!docume nt.all
function restrictinput(maxlength,e, placeholde r){
if (window.event&&event.srcEl ement.valu e.length>= maxlength)
return false
else if (e.target&&e.target==eval( placeholde r)&&e.targ et.value.l ength>=max length){
var pressedkey=/[a-zA-Z0-9\.\, \/]/ //detect alphanumeric keys
if (pressedkey.test(String.fr omCharCode (e.which)) )
e.stopPropagation()
}
}
function countlimit(maxlength,e,pla ceholder){
var theform=eval(placeholder)
var lengthleft=maxlength-thefo rm.value.l ength
var placeholderobj=document.al l? document.all[placeholder] : document.getElementById(pl aceholder)
if (window.event||e.target&&e .target==e val(placeh older)){
if (lengthleft<0)
theform.value=theform.valu e.substrin g(0,maxlen gth)
placeholderobj.innerHTML=l engthleft
}
}
function displaylimit(theform,theli mit){
var limit_text='<b><span id="'+theform.toString()+' ">'+thelim it+'</span ></b> characters remaining'
if (document.all||ns6)
document.write(limit_text)
if (document.all){
eval(theform).onkeypress=f unction(){ return restrictinput(thelimit,eve nt,theform )}
eval(theform).onkeyup=func tion(){ countlimit(thelimit,event, theform)}
}
else if (ns6){
document.body.addEventList ener('keyp ress', function(event) { restrictinput(thelimit,eve nt,theform ) }, true);
document.body.addEventList ener('keyu p', function(event) { countlimit(thelimit,event, theform) }, true);
}
}
SCRIPT TO HIGHLIGHT FIELDS:
var focusColor = '#E1E1E1';
var blurColor = '#ffffff';
function hotbox() {
var form, el, e, f = 0;
while (form = document.forms[f++]) {
e = 0;
while (el = form.elements[e++]) if (el.type == 'text' || el.type =='password' &&Â typeof el.style != 'undefined') {
el.onfocus = new Function('this.style.backg round = "' + focusColor + '";' + 'this.style.border = "1px solid #B1B1B1";');
el.onblur = new Function('this.style.backg round = "' + blurColor + '";' + 'this.style.border = "1px solid #B1B1B1";');
}
}
}
onload = hotbox;
EMAIL CONFIRMATION SCRIPT:
function checkEmail(REGISTRATION) {
  if (document.REGISTRATION.use rEmailOne. value != document.REGISTRATION.user EmailTwo.v alue)
  {
    alert('Those emails don\'t match!');
    return false;
  } else {
    return true;
  }
}
TOOLTIPS SCRIPTS:
function showtip(current,e,text)
{
  if (document.all)
  {
   thetitle=text.split('<br>' )
   if (thetitle.length > 1)
   {
    thetitles=""
    for (i=0; i<thetitle.length; i++)
      thetitles += thetitle[i] + "\r\n"
    current.title = thetitles
   }
   else current.title = text
  }
  else if (document.layers)
  {
    document.tooltip.document. write(
      '<layer bgColor="#FFFFE7" style="border:1px ' +
      'solid black; font-size:12px;color:#0000 00;">' + text + '</layer>')
    document.tooltip.document. close()
    document.tooltip.left=e.pa geX+5
    document.tooltip.top=e.pag eY+5
    document.tooltip.visibilit y="show"
  }
}
function hidetip()
{
  if (document.layers)
    document.tooltip.visibilit y="hidden"
}
It may just be a question of combining the functions I already have?
<div class="registrationForm" name="registrationForm">
<form name="REGISTRATION" method="POST" action="#" ID="Form1">
<div class="accountType">
<table width="452" border="0" cellpadding="2" cellspacing="0" class="registrationForm" ID="Table2">
 <tr>
  <td colspan="3" class="critical"><b>All fields in RED are required</b></td>
 </tr> Â
 <tr>
  <td colspan="3" class="sectionName">Choose
 </tr>
 <tr>
  <td colspan="3"><hr class="registrationForm"><
 </tr> Â
 <tr>
  <td class="critical">Account Type</td>
  <td class="field">
           <b>FREE ACCESS UNTIL - (date here)</b>
  </td>
  <td><a href="#" class="help" onmouseover="showtip(this,
 </tr>
</table>
</div>
<br>
<div class="address">
<table width="452" border="0" cellpadding="2" cellspacing="0" class="registrationForm" ID="Table1">
 <tr>
  <td colspan="3" class="sectionName">Person
 </tr>
 <tr>
  <td colspan="3"><hr class="registrationForm"><
 </tr> Â
 <tr>
  <td class="critical">Preferred
  <td class="field"><input type="text" class="registrationFormADD
  </td>
  <td><a href="#" class="help" onmouseover="showtip(this,
 </tr>
 <tr>
  <td class="critical"></td>
  <td class="characterCount">
  <script>
      displaylimit("document.REG
      </script>
  </td>
  <td></td>  Â
 </tr>
 <tr>
  <td class="critical">Your Email Address</td>
  <td class="field"><input type="text" class="registrationFormADD
      <td><a href="#" class="help" onmouseover="showtip(this,
 </tr>
 <tr>
  <td class="critical">Confirm Email</td>
  <td class="field"><input type="text" class="registrationFormADD
      <td><a href="#" class="help" onmouseover="showtip(this,
 </tr> Â
 <tr>
  <td class="critical">Password<
  <td class="field"><input type="password" class="registrationFormADD
      <td><a href="#" class="help" onmouseover="showtip(this,
 </tr>
 <tr>
  <td class="critical">Confirm Password</td>
  <td class="field"><input type="password" class="registrationFormADD
      <td><a href="#" class="help" onmouseover="showtip(this,
 </tr>
 <tr>
  <td class="field">Street Address</td>
  <td class="field"><input type="text" class="registrationFormADD
      <td><a href="#" class="help" onmouseover="showtip(this,
 </tr>
 <tr>
  <td>Village</td>
  <td class="field"><input type="text" class="registrationFormADD
      <td><a href="#" class="help" onmouseover="showtip(this,
 </tr>
 <tr>
  <td>Town</td>
  <td class="field"><input type="text" class="registrationFormADD
      <td><a href="#" class="help" onmouseover="showtip(this,
 </tr>
 <tr>
  <td class="critical">City</td>
  <td class="field"><input type="text" class="registrationFormADD
      <td><a href="#" class="help" onmouseover="showtip(this,
 </tr>
 <tr>
  <td class="field">County</td>
  <td class="field"><input type="text" class="registrationFormADD
      <td><a href="#" class="help" onmouseover="showtip(this,
 </tr>
 <tr>
  <td class="field">Postcode</td
  <td class="field"><input type="text" class="registrationFormADD
      <td><a href="#" class="help" onmouseover="showtip(this,
 </tr>
 <tr>
  <td class="critical">Country</
  <td class="field"><input type="text" class="registrationFormADD
      <td><a href="#" class="help" onmouseover="showtip(this,
 </tr>
 <tr>
  <td>Home Telephone</td>
  <td class="field"><input type="text" class="registrationFormADD
      <td><a href="#" class="help" onmouseover="showtip(this,
 </tr> Â
 <tr>
  <td>Mobile Telephone</td>
  <td class="field"><input type="text" class="registrationFormADD
      <td><a href="#" class="help" onmouseover="showtip(this,
 </tr>
 <tr>
  <td colspan="2" width="400"><b>You must accept the terms and conditions</b><input type="checkbox" name="TOS" ID="Checkbox1"></td>
      <td><a href="#" class="help" onmouseover="showtip(this,
 </tr>
 <tr>
  <td colspan="2" width="400"><INPUT type="submit" value="Submit" ID="Submit1" NAME="Submit1" onClick="checkEmail();"></
      <td><a href="#" class="help"></a></td>   Â
 </tr> Â
</form>
Â
</table>
</div>
SCRIPT FOR PAYMENT DETAILS:
var isIE=document.all?true:fal
var isDOM=document.getElementB
var isNS4=document.layers?true
/* _w : which ID (1) or (2) */
/* _h : (h)ide or (s)how */
function toggleT(_w,_h) {
 if (isDOM)
 {
  if (_h=='s') document.getElementById(_w
  if (_h=='h') document.getElementById(_w
 }
 else if (isIE) {
  if (_h=='s') eval("document.all."+_w+".
  if (_h=='h') eval("document.all."+_w+".
 }
 else if(isNS4)
 {
  if (_h=='s') eval("document.layers['"+_
  if (_h=='h') eval("document.layers['"+_
 }
}
SCRIPT TO COUNT REMAINING CHARACTERS:
var ns6=document.getElementByI
function restrictinput(maxlength,e,
if (window.event&&event.srcEl
return false
else if (e.target&&e.target==eval(
var pressedkey=/[a-zA-Z0-9\.\,
if (pressedkey.test(String.fr
e.stopPropagation()
}
}
function countlimit(maxlength,e,pla
var theform=eval(placeholder)
var lengthleft=maxlength-thefo
var placeholderobj=document.al
if (window.event||e.target&&e
if (lengthleft<0)
theform.value=theform.valu
placeholderobj.innerHTML=l
}
}
function displaylimit(theform,theli
var limit_text='<b><span id="'+theform.toString()+'
if (document.all||ns6)
document.write(limit_text)
if (document.all){
eval(theform).onkeypress=f
eval(theform).onkeyup=func
}
else if (ns6){
document.body.addEventList
document.body.addEventList
}
}
SCRIPT TO HIGHLIGHT FIELDS:
var focusColor = '#E1E1E1';
var blurColor = '#ffffff';
function hotbox() {
var form, el, e, f = 0;
while (form = document.forms[f++]) {
e = 0;
while (el = form.elements[e++]) if (el.type == 'text' || el.type =='password' &&Â typeof el.style != 'undefined') {
el.onfocus = new Function('this.style.backg
el.onblur = new Function('this.style.backg
}
}
}
onload = hotbox;
EMAIL CONFIRMATION SCRIPT:
function checkEmail(REGISTRATION) {
  if (document.REGISTRATION.use
  {
    alert('Those emails don\'t match!');
    return false;
  } else {
    return true;
  }
}
TOOLTIPS SCRIPTS:
function showtip(current,e,text)
{
  if (document.all)
  {
   thetitle=text.split('<br>'
   if (thetitle.length > 1)
   {
    thetitles=""
    for (i=0; i<thetitle.length; i++)
      thetitles += thetitle[i] + "\r\n"
    current.title = thetitles
   }
   else current.title = text
  }
  else if (document.layers)
  {
    document.tooltip.document.
      '<layer bgColor="#FFFFE7" style="border:1px ' +
      'solid black; font-size:12px;color:#0000
    document.tooltip.document.
    document.tooltip.left=e.pa
    document.tooltip.top=e.pag
    document.tooltip.visibilit
  }
}
function hidetip()
{
  if (document.layers)
    document.tooltip.visibilit
}
It may just be a question of combining the functions I already have?
Suggestion 1. For username : As soon as the user moves out from the username text box, pop up a window and in this window check for the existence of this particular username, and show the alert accordingly.
Or keep a button next to the username text box as check existence and as soon as the user clicks on it pop up a window and check for the usernames uniqueness.
In this way you do not leave the page and thus do not loose the filled up details
Suggetion for Email checks : this can be done as on submit call a function and validate each and every form element accordingly.
Also remember while validating a form inside a div it is better to put all the functions inside this layer, sometimes errors are thrown if the functions are put outside the div.
let me know...
Regards
Harish(hart).
Or keep a button next to the username text box as check existence and as soon as the user clicks on it pop up a window and check for the usernames uniqueness.
In this way you do not leave the page and thus do not loose the filled up details
Suggetion for Email checks : this can be done as on submit call a function and validate each and every form element accordingly.
Also remember while validating a form inside a div it is better to put all the functions inside this layer, sometimes errors are thrown if the functions are put outside the div.
let me know...
Regards
Harish(hart).
ASKER
could you tell me how to make a check username button please?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I will give it a go thanks, I presume that code works fine on asp?
it will itz just javascript.
Let me know...
Regards
Hart(harish)
Let me know...
Regards
Hart(harish)
ASKER
Ok, I think I have worked out that what I need is a submit button below my name field, titled check name available. When clicked this should check the db for a memberID field that = what is in name field. If the name is already taken it returns "choose another name" or otherwise "this name is available" right?
yes but check the username value in the db in a pop up screen.
so that you don't loose the main form..
just check my code and u will find how to do it..
Regards
Hart
so that you don't loose the main form..
just check my code and u will find how to do it..
Regards
Hart
ASKER