SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Member
    Join Date
    Oct 2006
    Posts
    22
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Javascript error problem

    Hello coders,

    I am having an issue with a script and was wondering if anyone could help on this.

    I have a script that submits a form to a database but when using the submit button I am getting a javascript error message in the browser saying that "document.update.password_old" has no propertes. I dont see any errors in the script. AND if there is I cant see it.
    here is the script:

    <SCRIPT LANGUAGE="JavaScript">
    function change_color_of_text_vars(var_name,var_color,var_weight){
    eval("document.getElementById('"+var_name+"').style.fontWeight='"+var_weight+" ';");
    eval("document.getElementById('"+var_name+"').style.color='"+var_color+"';");
    return;
    }
    function check_text_vars(){
    var message = "";
    if (document.update.password_old.value!=""||document.update.password_1.value!=""| |document.update.password_2.value!="") {
    if (document.update.password_old.value=="") {
    message = "please enter old password.";
    change_color_of_text_vars('password_old','FF0000','bold');
    }
    else if (document.update.password_1.value=="") {
    message = "please enter new password.";
    change_color_of_text_vars('password_1','FF0000','bold');
    }
    else if (document.update.password_2.value=="") {
    message = "please enter new password confirmation.";
    change_color_of_text_vars('password_2','FF0000','bold');
    }
    else if (document.update.password_1.value!=document.update.password_2.value) {
    message = "confirmation password does not match your initial password\nplease re-enter confirmation password..";
    change_color_of_text_vars('password_2','FF0000','bold');
    }
    }
    else if (document.update.fname.value=="") {
    message = "please enter first name.";
    change_color_of_text_vars('fname','FF0000','bold');
    }
    else if (document.update.lname.value=="") {
    message = "please enter last name.";
    change_color_of_text_vars('lname','FF0000','bold');
    }
    else if (document.update.address.value=="") {
    message = "please enter address.";
    change_color_of_text_vars('address','FF0000','bold');
    }
    else if (document.update.city.value=="") {
    message = "please enter city.";
    change_color_of_text_vars('city','FF0000','bold');
    }
    else if (document.update.state.value=="") {
    message = "please enter state/province.";
    change_color_of_text_vars('state','FF0000','bold');
    }
    else if (document.update.zipcode.value=="") {
    message = "please enter zipcode.";
    change_color_of_text_vars('zipcode','FF0000','bold');
    }
    else if (document.update.countryID.options[document.update.countryID.selectedIndex].value=="0") {
    message = "please select country.";
    change_color_of_text_vars('country','FF0000','bold');
    }
    else if (document.update.cpref[0].checked) {
    if (document.update.hphone_cc.value=="") {
    message = "please enter home phone country code.";
    change_color_of_text_vars('hphone','FF0000','bold');
    }
    else if (document.update.hphone_ac.value=="") {
    message = "please enter home phone area code.";
    change_color_of_text_vars('hphone','FF0000','bold');
    }
    else if (document.update.hphone_n.value=="") {
    message = "please enter home phone number.";
    change_color_of_text_vars('hphone','FF0000','bold');
    }
    }
    else if (document.update.email.value=="") {
    message = "please enter email.";
    change_color_of_text_vars('email','FF0000','bold');
    }
    if (message!="") {
    alert(message);
    return false;
    } else return true;
    }
    function activate(selection,varname) {
    if (selection.checked)
    change_color_of_text_vars(varname,'616130','bold');
    else
    change_color_of_text_vars(varname,'616130','normal');
    }
    function initialize() {
    change_color_of_text_vars('password_1','616130','bold');
    change_color_of_text_vars('password_2','616130','bold');
    change_color_of_text_vars('password_old','616130','bold');
    change_color_of_text_vars('fname','616130','bold');
    change_color_of_text_vars('lname','616130','bold');
    change_color_of_text_vars('address','616130','bold');
    change_color_of_text_vars('city','616130','bold');
    change_color_of_text_vars('state','616130','bold');
    change_color_of_text_vars('zipcode','616130','bold');
    change_color_of_text_vars('country','616130','bold');
    change_color_of_text_vars('hphone','616130','normal');
    change_color_of_text_vars('email','616130','bold');
    return;
    }
    function submit_form(){
    document.update.submit_btn.disabled = true;
    document.update.submit_btn.value='Processing...';
    document.update.submit();
    }
    function main(){
    initialize();
    if (check_text_vars())
    submit_form();
    }
    document.getElementById("back_btn").style.visibility = "visible";
    </SCRIPT>

    Then in the button I am using this:
    <INPUT TYPE="Button" NAME="submit_btn" VALUE="Save Changes" ONCLICK="main();return false;" CLASS="submit_btn">

    Much thanks to anyone who can figure this one out because I am stumped..

    I appreciate any comments and send thanks in advance.

  2. #2
    SitePoint Evangelist
    Join Date
    Jul 2007
    Posts
    345
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Can you post the html for your form?

    A side issue:
    Code:
    function change_color_of_text_vars(var_name,var_color,var_weight){
      eval("document.getElementById('"+var_name+"').style.fontWeight='"+var_weight+" ';");
      eval("document.getElementById('"+var_name+"').style.color='"+var_color+"';");
      return;
    }
    
    // could be
    function change_color_of_text_vars(var_name,var_color,var_weight){
      var element = document.getElementById(var_name);
      element.style.fontWeight = var_weight;
      element.style.color = var_color;
      return;
    }
    No need for those eval statements.
    }

  3. #3
    SitePoint Member
    Join Date
    Oct 2006
    Posts
    22
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I am unable to post the form because of the 10 image rule. The form has over 31 images in it so its not allowing me to post.

  4. #4
    SitePoint Member
    Join Date
    Oct 2006
    Posts
    22
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    img tags removed:

    HTML Code:
    <FORM NAME="update" ACTION="/executeprocess.cfm?ProcessID=b_webusers_account&buyerid=<CFOUTPUT>#buyerid#</CFOUTPUT>" METHOD="POST">
    		<TD VALIGN="top" ID="outline">
    			<CFINCLUDE TEMPLATE="../error_message.cfm">
    			<CFINCLUDE TEMPLATE="webusers_tabs.cfm">
    			<TABLE WIDTH="100%" CELLPADDING="0" CELLSPACING="0" BORDER="0" CLASS="innertbl">
    				<TR><TD WIDTH="24%"><B ID="username">Username :</B></TD><TD><CFOUTPUT>#username#</CFOUTPUT></TD></TR>
    				<TR><TD COLSPAN="2">&nbsp;</TD></TR>
    				<TR><TD WIDTH="24%"><B ID="password_old">Old Password :</B></TD><TD><INPUT TYPE="Password" NAME="password_old" VALUE="" SIZE="20" MAXLENGTH="20" <CFIF NOT BitAnd(ps.editWebUser,BUAccessLevel)>DISABLED</CFIF>> (leave blank if password is unchanged)</TD></TR>
    				<TR><TD COLSPAN="2">&nbsp;</TD></TR>
    				<TR><TD WIDTH="24%"><B ID="password_1" COLOR="8B8B8B">New Password :</B></TD><TD><INPUT TYPE="Password" NAME="password_1" VALUE="" SIZE="20" MAXLENGTH="20" <CFIF NOT BitAnd(ps.editWebUser,BUAccessLevel)>DISABLED</CFIF>> (leave blank if password is unchanged)</TD></TR>
    				<TR><TD COLSPAN="2">&nbsp;</TD></TR>
    				<TR><TD WIDTH="24%"><B ID="password_2" COLOR="8B8B8B">Confirm New Password :</B></TD><TD><INPUT TYPE="Password" NAME="password_2" VALUE="" SIZE="20" MAXLENGTH="20" <CFIF NOT BitAnd(ps.editWebUser,BUAccessLevel)>DISABLED</CFIF>> (leave blank if password is unchanged)</TD></TR>
    				<TR><TD COLSPAN="2">&nbsp;</TD></TR>
    			</TABLE>
    			<TABLE WIDTH="100%" CELLSPACING="0" CELLPADDING="0" BORDER="0">
    				<TR><TD VALIGN="middle" CLASS="reg_txt_hd">Personal Information</TD></TR>
    				<TR><TD>&nbsp;</TD></TR>
    			</TABLE>
    			<TABLE WIDTH="100%" CELLPADDING="0" CELLSPACING="0" BORDER="0" CLASS="innertbl">
    				<TR><TD WIDTH="24%"><B ID="fname">First name :</B></TD><TD><INPUT TYPE="Text" NAME="fname" VALUE="<CFOUTPUT>#fname#</CFOUTPUT>" SIZE="50" MAXLENGTH="50" <CFIF NOT BitAnd(ps.editWebUser,BUAccessLevel)>DISABLED</CFIF>></TD></TR>
    				<TR><TD COLSPAN="2">&nbsp;</TD></TR>
    				<TR><TD WIDTH="24%">Middle name :</TD><TD><INPUT TYPE="Text" NAME="mname" VALUE="<CFOUTPUT>#mname#</CFOUTPUT>" SIZE="50" MAXLENGTH="50" <CFIF NOT BitAnd(ps.editWebUser,BUAccessLevel)>DISABLED</CFIF>> (optional)</TD></TR>
    				<TR><TD COLSPAN="2">&nbsp;</TD></TR>
    				<TR><TD WIDTH="24%"><B ID="lname">Last name :</B></TD><TD><INPUT TYPE="Text" NAME="lname" VALUE="<CFOUTPUT>#lname#</CFOUTPUT>" SIZE="50" MAXLENGTH="50" <CFIF NOT BitAnd(ps.editWebUser,BUAccessLevel)>DISABLED</CFIF>></TD></TR>
    				<TR><TD COLSPAN="2">&nbsp;</TD></TR>
    				<TR><TD WIDTH="24%"><B ID="address">Address :</B></TD><TD><INPUT TYPE="Text" NAME="address" VALUE="<CFOUTPUT>#address#</CFOUTPUT>" SIZE="70" MAXLENGTH="100" <CFIF NOT BitAnd(ps.editWebUser,BUAccessLevel)>DISABLED</CFIF>></TD></TR>
    				<TR><TD COLSPAN="2">&nbsp;</TD></TR>
    				<TR><TD WIDTH="24%"><B ID="city">City :</B></TD><TD><INPUT TYPE="Text" NAME="city" VALUE="<CFOUTPUT>#city#</CFOUTPUT>" SIZE="50" MAXLENGTH="50" <CFIF NOT BitAnd(ps.editWebUser,BUAccessLevel)>DISABLED</CFIF>></TD></TR>
    				<TR><TD COLSPAN="2">&nbsp;</TD></TR>
    				<TR><TD WIDTH="24%"><B ID="state">State/Province :</B></TD><TD><INPUT TYPE="Text" NAME="state" VALUE="<CFOUTPUT>#state#</CFOUTPUT>" SIZE="50" MAXLENGTH="50" <CFIF NOT BitAnd(ps.editWebUser,BUAccessLevel)>DISABLED</CFIF>></TD></TR>
    				<TR><TD COLSPAN="2">&nbsp;</TD></TR>
    				<TR><TD WIDTH="24%"><B ID="zipcode">Zipcode :</B></TD><TD><INPUT TYPE="Text" NAME="zipcode" VALUE="<CFOUTPUT>#zipcode#</CFOUTPUT>" SIZE="15" MAXLENGTH="15" <CFIF NOT BitAnd(ps.editWebUser,BUAccessLevel)>DISABLED</CFIF>></TD></TR>
    				<TR><TD COLSPAN="2">&nbsp;</TD></TR>
    				<TR><TD WIDTH="24%"><B ID="country">Country :</B></TD><TD><SELECT NAME="countryID" <CFIF NOT BitAnd(ps.editWebUser,BUAccessLevel)>DISABLED</CFIF>><OPTION VALUE="0" <CFIF countryID EQ 0>SELECTED</CFIF>>&lt;select country&gt;<CFOUTPUT QUERY="gCountry"><OPTION VALUE="#ID#" <CFIF countryID EQ ID>SELECTED</CFIF>>#Country#</CFOUTPUT></SELECT></TD></TR>
    				<TR><TD COLSPAN="2">&nbsp;</TD></TR>
    				<TR><TD WIDTH="24%">&nbsp;</TD><TD ID="tip">Country:Area:Phone #:Ext:</TD></TR>
    				<TR><TD WIDTH="24%"><FONT ID="hphone">Home phone :</FONT></TD><TD><INPUT TYPE="Text" NAME="hphone_cc" VALUE="<CFOUTPUT>#hphone_cc#</CFOUTPUT>" SIZE="3" MAXLENGTH="3" <CFIF NOT BitAnd(ps.editWebUser,BUAccessLevel)>DISABLED</CFIF>>&nbsp;<INPUT TYPE="Text" NAME="hphone_ac" VALUE="<CFOUTPUT>#hphone_ac#</CFOUTPUT>" SIZE="4" MAXLENGTH="4" <CFIF NOT BitAnd(ps.editWebUser,BUAccessLevel)>DISABLED</CFIF>>&nbsp;<INPUT TYPE="Text" NAME="hphone_n" VALUE="<CFOUTPUT>#hphone_n#</CFOUTPUT>" SIZE="15" MAXLENGTH="15" <CFIF NOT BitAnd(ps.editWebUser,BUAccessLevel)>DISABLED</CFIF>>&nbsp;<INPUT TYPE="Text" NAME="hphone_ext" VALUE="<CFOUTPUT>#hphone_ext#</CFOUTPUT>" SIZE="5" MAXLENGTH="5" <CFIF NOT BitAnd(ps.editWebUser,BUAccessLevel)>DISABLED</CFIF>> (optional)</TD></TR>
    				<TR><TD WIDTH="24%">&nbsp;</TD><TD ID="tip">Country:Area:Phone #:Ext:</TD></TR>
    				<TR><TD WIDTH="24%">Work phone :</TD><TD><INPUT TYPE="Text" NAME="wphone_cc" VALUE="<CFOUTPUT>#wphone_cc#</CFOUTPUT>" SIZE="3" MAXLENGTH="3" <CFIF NOT BitAnd(ps.editWebUser,BUAccessLevel)>DISABLED</CFIF>>&nbsp;<INPUT TYPE="Text" NAME="wphone_ac" VALUE="<CFOUTPUT>#wphone_ac#</CFOUTPUT>" SIZE="4" MAXLENGTH="4" <CFIF NOT BitAnd(ps.editWebUser,BUAccessLevel)>DISABLED</CFIF>>&nbsp;<INPUT TYPE="Text" NAME="wphone_n" VALUE="<CFOUTPUT>#wphone_n#</CFOUTPUT>" SIZE="15" MAXLENGTH="15" <CFIF NOT BitAnd(ps.editWebUser,BUAccessLevel)>DISABLED</CFIF>>&nbsp;<INPUT TYPE="Text" NAME="wphone_ext" VALUE="<CFOUTPUT>#wphone_ext#</CFOUTPUT>" SIZE="5" MAXLENGTH="5" <CFIF NOT BitAnd(ps.editWebUser,BUAccessLevel)>DISABLED</CFIF>> (optional)</TD></TR>						
    				<TR><TD WIDTH="24%">&nbsp;</TD><TD ID="tip">Country:Area:Phone #:</TD></TR>
    				<TR><TD WIDTH="24%">Mibile phone :</TD><TD><INPUT TYPE="Text" NAME="mphone_cc" VALUE="<CFOUTPUT>#mphone_cc#</CFOUTPUT>" SIZE="3" MAXLENGTH="3" <CFIF NOT BitAnd(ps.editWebUser,BUAccessLevel)>DISABLED</CFIF>>&nbsp;<INPUT TYPE="Text" NAME="mphone_ac" VALUE="<CFOUTPUT>#mphone_ac#</CFOUTPUT>" SIZE="4" MAXLENGTH="4" <CFIF NOT BitAnd(ps.editWebUser,BUAccessLevel)>DISABLED</CFIF>>&nbsp;<INPUT TYPE="Text" NAME="mphone_n" VALUE="<CFOUTPUT>#mphone_n#</CFOUTPUT>" SIZE="15" MAXLENGTH="15" <CFIF NOT BitAnd(ps.editWebUser,BUAccessLevel)>DISABLED</CFIF>> (optional)</TD></TR>
    				<TR><TD WIDTH="24%">&nbsp;</TD><TD ID="tip">Country:Area:Phone #:</TD></TR>
    				<TR><TD WIDTH="24%">Fax :</TD><TD><INPUT TYPE="Text" NAME="fax_cc" VALUE="<CFOUTPUT>#fax_cc#</CFOUTPUT>" SIZE="3" MAXLENGTH="3" <CFIF NOT BitAnd(ps.editWebUser,BUAccessLevel)>DISABLED</CFIF>>&nbsp;<INPUT TYPE="Text" NAME="fax_ac" VALUE="<CFOUTPUT>#fax_ac#</CFOUTPUT>" SIZE="4" MAXLENGTH="4" <CFIF NOT BitAnd(ps.editWebUser,BUAccessLevel)>DISABLED</CFIF>>&nbsp;<INPUT TYPE="Text" NAME="fax_n" VALUE="<CFOUTPUT>#fax_n#</CFOUTPUT>" SIZE="15" MAXLENGTH="15" <CFIF NOT BitAnd(ps.editWebUser,BUAccessLevel)>DISABLED</CFIF>> (optional)</TD></TR>
    				<TR><TD WIDTH="24%">&nbsp;</TD><TD ID="tip">Tip: You can enter an international phone number above; for the United States the coutry code is "1".</TD></TR>
    				<TR><TD COLSPAN="2">&nbsp;</TD></TR>
    				<TR><TD WIDTH="24%"><B ID="email">Email :</B></TD><TD><INPUT TYPE="Text" NAME="email" VALUE="<CFOUTPUT>#email#</CFOUTPUT>" SIZE="50" MAXLENGTH="180" <CFIF NOT BitAnd(ps.editWebUser,BUAccessLevel)>DISABLED</CFIF>></TD></TR>
    				<TR><TD COLSPAN="2">&nbsp;</TD></TR>
    			</TABLE>
    			<TABLE WIDTH="100%" CELLSPACING="0" CELLPADDING="0" BORDER="0">
    				<TR><TD VALIGN="middle" CLASS="reg_txt_hd">Contact Preference</TD></TR>
    				<TR><TD>&nbsp;</TD></TR>
    			</TABLE>
    			<TABLE WIDTH="100%" CELLPADDING="0" CELLSPACING="0" BORDER="0" CLASS="innertbl">
    				<TR><TD WIDTH="24%" ALIGN="center"><INPUT ID="checkbox" TYPE="Checkbox" NAME="cpref" VALUE="1" <CFIF BitAnd(cpref,1)> CHECKED</CFIF> ONCLICK="activate(this,'hphone');" <CFIF NOT BitAnd(ps.editWebUser,BUAccessLevel)>DISABLED</CFIF>></TD><TD CLASS="default_txt">By Phone</TD></TR>
    				<TR><TD COLSPAN="2">&nbsp;</TD></TR>
    				<TR><TD WIDTH="24%" ALIGN="center"><INPUT ID="checkbox" TYPE="Checkbox" NAME="cpref" VALUE="2" <CFIF BitAnd(cpref,2)> CHECKED</CFIF> <CFIF NOT BitAnd(ps.editWebUser,BUAccessLevel)>DISABLED</CFIF>></TD><TD CLASS="default_txt">By Email</TD></TR>
    				<TR><TD COLSPAN="2">&nbsp;</TD></TR>
    				<TR><TD WIDTH="24%" ALIGN="center"><INPUT ID="checkbox" TYPE="Checkbox" NAME="cpref" VALUE="4" <CFIF BitAnd(cpref,4)> CHECKED</CFIF> <CFIF NOT BitAnd(ps.editWebUser,BUAccessLevel)>DISABLED</CFIF>></TD><TD CLASS="default_txt">By Mail</TD></TR>
    			</TABLE>
    			<TABLE WIDTH="300" CELLPADDING="0" CELLSPACING="0" BORDER="0" STYLE="margin-top: 15px;">
    				<TR>
    					<TD STYLE="background-color:#FFCACA;border-style:dotted;border-width:1px;border-color:#970000;">
    						<TABLE WIDTH="300" CELLPADDING="0" CELLSPACING="0" BORDER="0" CLASS="reg_txt_red">
    							<TR><TD COLSPAN="3">&nbsp;</TD></TR>
    							<TR>
    								<TD WIDTH="10">&nbsp;</TD>
    								<TD WIDTH="280" VALIGN="top"><INPUT TYPE="Checkbox" NAME="isactive" VALUE="1" <CFIF isactive>checked="checked"</CFIF> <CFIF NOT BitAnd(ps.editWebUser,BUAccessLevel)>DISABLED</CFIF>> <B>Enable User Account</B></TD>
    								<TD WIDTH="10">&nbsp;</TD>
    							</TR>
    							<TR><TD COLSPAN="3">&nbsp;</TD></TR>
    						</TABLE>
    					</TD>
    				</TR>
    			</TABLE>[HIGHLIGHT="HTML4Strict"][HIGHLIGHT="HTML4Strict"][/HIGHLIGHT][/HIGHLIGHT]
    			<!--- submit button --->
    			 <CFIF BitAnd(ps.editWebUser,BUAccessLevel)>
    				<TABLE WIDTH="150" CELLPADDING="0" CELLSPACING="0" BORDER="0" STYLE="margin-top: 20px;">
    					<TR><TD WIDTH="150"><INPUT TYPE="Button" NAME="submit_btn" VALUE="Save Changes" ONCLICK="main();return false;" CLASS="submit_btn"></TD></FORM></TR>
    				</TABLE>
    			</CFIF>
    		</TD></FORM>

  5. #5
    SitePoint Evangelist
    Join Date
    Jul 2007
    Posts
    345
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Maybe give the inputs ids and use document.getElementById rather than document.update.password_old. Could the <B> element id and the <INPUT> name having the same value be confusing the browser?


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •