Wrox Home  
Search P2P Archive for: Go

  Return to Index  

javascript_howto thread: Need help


Message #1 by "shiraz" <sheeraz3@y...> on Fri, 22 Mar 2002 02:06:49 +0500
This is a multi-part message in MIME format.

------=_NextPart_000_0017_01C1D146.39F66710
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable


Hye:
 I am trying to make a registration page .i this all of the data is 
stored in (one dimention) arrays, when a member fill the form and then 
click on the submit button , a new window will open which will show all 
of the entries that was enter by the user. In this every thing what i 
made is fine but i have only two problems which i can't debug:

1- in the occupation field, the value comes out is the index of the 
option box not the text which is placed on that index..

2- It give a Runtime error:" OBJECT DOESN'T SUPPORT THIS PROPERTY OR 
METHOD" on the statement where I am trying to increment P:   p++


Given bellow is the code:

*************************************************************************
*******



<html>

<head>
  <title></title>
  <SCRIPT language=3DJavaScript>
 
var Members=3Dnew Array();
var p=3D0;
var 
name=3D"",login=3D"",password=3D"",Confirmpassword=3D"",occupation=3D"",d
ateofbirth=3D"",address=3D"",country=3D"",city=3D"",state=3D"",postalcode
=3D"",telephone=3D"",fax=3D"",email=3D"",nic=3D"";
var 
nam,logi=3D"",passwor=3D"",confoasswor=3D"",occupatio=3D"",dateofbirt=3D"
",addres=3D"",countr=3D"",cit=3D"",stat=3D"",postalcod=3D"",telephon=3D""
,fa=3D"",emai=3D"",ni=3D"";
 

function IsBlank(s){
 if(s.charAt(0)=3D=3D"")
  return true
 else
  return false
}

function checklength(str){
var minLength=3D5;
 if (str.length < minLength) {
  alert('Your password must be at least ' + minLength + ' characters 
long. Try again.');

 return false;

 }
return true;
}

function Validate_Name(str){
 //var str=3Ddocument.REG.fname.value;
 if(IsBlank(str)){
alert(" the Name field cannot be empty or cannot have leading spaces")
return false
}
return true
}

function Validate_LoginName(str){
 //var str=3Ddocument.REG.Blogin.value;
 if(IsBlank(str)){
alert("Log-in cannot be empty and cannot have leading spaces")
return false
}
return true
}

function Check_Password(str){
 //var str=3Ddocument.REG.pwd.value;
 if(IsBlank(str)){
  alert("Password cannot be empty or cannot have leading spaces")
  return false
 }
 return true
}

function Validate_Password(str1,str2){
 //var str1=3Ddocument.REG.pwd.value;
 //var str2=3Ddocument.REG.conf_pwd.value;
 if(!(str1=3D=3Dstr2)){
  alert("Password does not matches")
  return false
 }
 return true
}

function Check_country(str){
 //var str=3Ddocument.REG.relg.value;
 if(IsBlank(str)){
  alert(" Please enter your Country")
  return false
 }
return true;
}

function Check_city(str){
 //var str=3Ddocument.REG.relg.value;
 if(IsBlank(str)){
  alert(" Please enter your City")
  return false
 }
return true;
}

function Check_postalcode(str){
 //var str=3Ddocument.REG.relg.value;
 if(IsBlank(str)){
  alert(" Please enter your Postal Code")
  return false
 }
return true;
}

function Check_state(str){
 //var str=3Ddocument.REG.relg.value;
 if(IsBlank(str)){
  alert(" Please enter your State")
  return false
 }
return true;
}


function Validate_Email(str){

 //var str=3Ddocument.REG.e_add.value;

 if(IsBlank(str)){
  alert(" the email field cannot be empty or cannot have leading 
spaces")
  return false
 }

 if(IsValid(str)){
  return true
 }
 return false
}



function Check_Occupation(str1){
 //var str1=3Ddocument.REG.ocpt.value;
 if(str1=3D=3D0){
  alert("Please select Occupation")
  return false
 }
 return true
}


function Check_Add(str){

 //var str=3Ddocument.REG.Add1.value;
 if(IsBlank(str)){
  alert(" Please enter your Address")
  return false
 }
return true;
}


function Check_NIC(str){
 //var str=3Ddocument.REG.nic1.value
 if(IsBlank(str)){
  alert(" Please enter your National ID card number")
  return false
 }
return true;
}




function IsValid(str){
var at,dot;
 len=3Dstr.length
  for(i=3D0;i<len;i++){
   if(str.charAt(i)=3D=3D"@"){
    at=3Dtrue;   
   }
   if(str.charAt(i)=3D=3D"."){
    dot=3Dtrue;
   }
   if (at=3D=3Dtrue && dot=3D=3Dtrue){
   return true;
   break;
   }
  } 
  alert("you have entered invalid E-Mail address");
 
return false;
}


function 
Member(name,login,password,confirmpassword,occupation,dateofbirth,address
,country,city,state,postalcode,fax,email,nic){
this.nam=3Dname;
this.logi=3Dlogin;
this.passwor=3Dpassword;
this.confirmpasswor=3Dconfirmpassword;
this.occupatio=3Doccupation;
this.dateofbirt=3Ddateofbirth;
this.addres=3Daddress;
this.countr=3Dcountry;
this.cit=3Dcity;
this.stat=3Dstate;
this.postalcod=3Dpostalcode;
this.telephon=3Dtelephone;
this.fa=3Dfax;
this.emai=3Demail;
this.ni=3Dnic;


}



function processForm(){
if(!Validate_Name(document.REGIS.mname.value)) return false
if(!Validate_LoginName(document.REGIS.mlname.value))return false
if(!Check_Password(document.REGIS.mpwd.value))return false
if(!checklength(document.REGIS.mpwd.value))return false
if(!Validate_Password(document.REGIS.mpwd.value,document.REGIS.mrpwd.valu
e ))return false
if(!Check_Occupation(document.REGIS.moccu.value))return false
if(!Check_Add(document.REGIS.maddress.value))return false
if(!Check_country(document.REGIS.mcountry.value))return false
if(!Check_city(document.REGIS.mcity.value))return false
if(!Check_state(document.REGIS.mstate.value))return false
if(!Check_postalcode(document.REGIS.mpcode.value))return false
if(!Validate_Email(document.REGIS.memail.value))return false
if(!Check_NIC(document.REGIS.mnic.value))return false

name=3Ddocument.REGIS.mname.value;
login=3Ddocument.REGIS.mlname.value;
password=3Ddocument.REGIS.mpwd.value;
confirmpassword=3Ddocument.REGIS.mpwd.value,document.REGIS.mrpwd.value;
occupation=3Ddocument.REGIS.moccu.options[document.REGIS.moccu.selectedIn
dex].value;
dateofbirth=3Ddocument.REGIS.mdofb.value;
address=3Ddocument.REGIS.maddress.value;
country=3Ddocument.REGIS.mcountry.value;
city=3Ddocument.REGIS.mcity.value;
state=3Ddocument.REGIS.mstate.value;
postalcode=3Ddocument.REGIS.mpcode.value;
telephone=3Ddocument.REGIS.mtelephone.value;
fax=3Ddocument.REGIS.mfax.value;
email=3Ddocument.REGIS.memail.value;
nic=3Ddocument.REGIS.mnic.value;

mem=3D new 
Member(name,login,password,confirmpassword,occupation,dateofbirth,address
,country,city,state,postalcode,telephone,fax,email,nic);

Members[p]=3Dmem;



isp=3Dopen("","result");

isp.document.write("<TITLE> Result Page</TITLE>"+"<PRE>")
isp.document.write("<H1 Align=3D'CENTER'>"+"Thank You for 
Registration"+"</H1>"+"<br>"+"<h2 Align=3D'CENTER'>"+"Please confirm 
Your Data Entry"+"</h2>"+"<HR>"+"<BR><BR>")
isp.document.write("Name\t\t\t:"+Members[p].nam+"<BR>")
isp.document.write("Login Name\t\t:"+Members[p].logi+"<BR>")
isp.document.write("Password\t\t:"+Members[p].passwor+"<BR>")
isp.document.write("Occupation\t\t:"+Members[p].occupatio+"<BR>")
isp.document.write("Date of Birth\t\t\t:"+Members[p].dateofbirt+"<BR>")
isp.document.write("Address\t\t\t:"+Members[p].addres+"<BR>")
isp.document.write("Country\t\t:"+Members[p].countr+"<BR>")
isp.document.write("City\t\t\t:"+Members[p].cit+"<br>")
isp.document.write("State\t\t:"+Members[p].stat+"<br>")
isp.document.write("Postal Code\t\t:"+Members[p].postalcod+"<br>")
isp.document.write("Telephone no.\t\t:"+Members[p].telephon+"<br>")
isp.document.write("Fax\t\t:"+Members[p].fa+"<br>")
isp.document.write("E-mail Address:\t\t:"+Members[p].emai+"<br>")
isp.document.write("NIC no.\t\t:"+Members[p].ni+"<br>")

isp.document.write("</PRE>");
if (isp.confirm("Is this information correct?"))
isp.close();
p++;
document.REGIS.reset();

}

</SCRIPT>

</head>
<BODY bgcolor=3D"#cccc99"><CENTER>
<TABLE align=3Dcenter border=3D0>
  <TBODY>
  <TR>
    <TD>MEMBER NAME
    <TD><INPUT id=3Dlogin name=3Dlogin size=3D"20">
  <TR>
    <TD>PASSWORD
    <TD><INPUT id=3Dpassword name=3Dpassword type=3Dpassword 
size=3D"20">
  <TR>
    <TD>
    <TD>
  <TR>
    <TD><INPUT id=3Dsubmit name=3Dsubmitbutton onclick=3DcheckPath(); 
type=3Dbutton value=3DSubmit></A></TD></TR></TBODY></TABLE>
<CENTER><BR><BR>
<TABLE cellpadding=3D"1" cellspacing=3D"4" WIDTH=3D"700">
<caption>
<B><FONT FACE=3D"Garamond"><FONT SIZE=3D"5" 
COLOR=3D"#666633">REGISTRATION 
FORM</B><hr size=3D"5" color=3D"#666633"><br>
</font>
</caption>

<FORM name=3DREGIS>
<font face=3D"courier new">
<TR>
<TD>Name :</TD>
<TD><INPUT TYPE=3D"TEXT" NAME=3D"mname" SIZE=3D"25" MAXLENGTH=3D"25" 
VALUE=3D""><FONT color=3Dred size=3D2>  *</FONT></TD>
</TR>

<TR>
<TD>Login Name :</TD>
<TD><INPUT TYPE=3D"TEXT" NAME=3D"mlname" SIZE=3D"25" MAXLENGTH=3D"25" 
VALUE=3D""><FONT color=3Dred size=3D2>  *</FONT>
</TD>
</TR>

<TR>
<TD>Password :</TD>
<TD><INPUT TYPE=3D"TEXT" NAME=3D"mpwd" SIZE=3D"25" MAXLENGTH=3D"25" 
VALUE=3D""><FONT color=3Dred size=3D2>  *</FONT>
</TD>
</TR>

<TR>
<TD>Reenter password :</TD>
<TD><INPUT TYPE=3D"TEXT" NAME=3D"mrpwd" SIZE=3D"25" MAXLENGTH=3D"25" 
VALUE=3D""><FONT color=3Dred size=3D2>  *</FONT>
</TD>
</TR>

<TR>
    <TD>Select Occupation</td>
    <TD colSpan=3D2><SELECT id=3Dmoccu name=3Dmoccu style=3D"WIDTH: 
152px">
    <OPTION selected value=3D"">
    <OPTION value=3D1>Student
    <OPTION value=3D2>banking/finance
    <OPTION value=3D3>Computer related
    <OPTION value=3D4>lower Class Business
    <OPTION value=3D5>medium Class Business
    <OPTION value=3D6>Upper Class Business
    <OPTION value=3D7>engineering/construction
    <OPTION value=3D8>Industrial Job
    <OPTION value=3D9>Government
    <OPTION value=3D10>Own Business
    <OPTION value=3D11>Doctor
    <OPTION value=3D12>Agriculturist
    <OPTION value=3D13>government Officer
    <OPTION value=3D14>unemployed
    </OPTION>
    </SELECT>
    <FONT color=3Dred size=3D2>  *</FONT>
    </td>
  </TR>

  <TR>
<TD>Date of Birth :</TD>
<TD><INPUT TYPE=3D"TEXT" NAME=3D"mdofb" SIZE=3D"25" MAXLENGTH=3D"25" 
VALUE=3D"">
</TD>
</TR>

<TR>
<TD>Address :</TD>
<TD><INPUT TYPE=3D"TEXT" NAME=3D"maddress" SIZE=3D"50" MAXLENGTH=3D"60" 
VALUE=3D""><FONT color=3Dred size=3D2>  *</FONT>
</TD>
</TR>
<TR>
<TD>Country :</TD>
<TD><INPUT TYPE=3D"TEXT" NAME=3D"mcountry" SIZE=3D"50" MAXLENGTH=3D"30" 
VALUE=3D""><FONT color=3Dred size=3D2>  *</FONT>
</TD>
</TR>
<TR>
<TD>City :</TD>
<TD><INPUT TYPE=3D"TEXT" NAME=3D"mcity" SIZE=3D"25" MAXLENGTH=3D"15" 
VALUE=3D""><FONT color=3Dred size=3D2>  *</FONT>
State :<INPUT TYPE=3D"TEXT" NAME=3D"mstate" SIZE=3D"25" MAXLENGTH=3D"15" 
VALUE=3D""><FONT color=3Dred size=3D2>  *</FONT>
</td>
</tr>

<TR>
<TD>Postal code :</TD>
<TD><INPUT TYPE=3D"TEXT" NAME=3D"mpcode" SIZE=3D"29" MAXLENGTH=3D"30" 
VALUE=3D""><FONT color=3Dred size=3D2>  *</FONT>
</TD>
</TR>
<TR>
<TD>Telephone :</TD>
<TD><INPUT TYPE=3D"TEXT" NAME=3D"mtelephone" SIZE=3D"50" 
MAXLENGTH=3D"30" VALUE=3D"">
</TD>
</TR>

<TR>
<TD>Fax :</TD>
<TD><INPUT TYPE=3D"TEXT" NAME=3D"mfax" SIZE=3D"29" MAXLENGTH=3D"30" 
VALUE=3D"">
</TD>
</TR>
<TR>
<TD>E-mail :</TD>
<TD><INPUT TYPE=3D"TEXT" NAME=3D"memail" SIZE=3D"29" MAXLENGTH=3D"30" 
VALUE=3D""><FONT color=3Dred size=3D2>  *</FONT>
</TD>
</TR>

<TR>
<TD>N.I.C no. :</TD>
<TD><INPUT TYPE=3D"TEXT" NAME=3D"mnic" SIZE=3D"29" MAXLENGTH=3D"30" 
VALUE=3D""><FONT color=3Dred size=3D2>  *</FONT>
</TD>
</TR>

</TABLE>
<BR><BR>
<CENTER><INPUT id=3Dbutton1 name=3Dbutton1 onclick=3DprocessForm(); 
type=3Dbutton value=3D"Submit Form">    <INPUT id=3Dreset name=3Dreset 
type=3Dreset value=3DReset></FORM>
<BR><BR><BR><BR>

<hr align=3D"center" width=3D"70%"size=3D"4" color=3D"#003300">

<TABLE>
  <TBODY>
  <TR>
    <TD align=3Dleft vAlign=3Dtop>
      <DIV ><A
      href=3D"home.htm">Home</A> <A
      href=3D"hotellocation.htm">Hotel Location
      </A> <A href=3D"restaurant.htm">Restaurant</A> <A 
href=3D"Rooms.htm">Rooms
      </A> <A href=3D"Photogallery.htm">Photo Gallery</A></TD></TR>
   <TR ALIGN=3D"MIDDLE"><TD><A
      href=3D"reservation.htm">Online Reservation</A> <A
      href=3D"services.htm">Services
      Offered</A> <A
      href=3D"aboutus.htm">About
      Us</A></TD></TR></DIV>
   </TBODY>
   </TABLE>
  
</body>
</html>


*************************************************************************
****************




_________________________________________________________

Do You Yahoo!?

Get your free @yahoo.com address at http://mail.yahoo.com




  Return to Index