samporras Posted February 21, 2005 Posted February 21, 2005 hey guys. I'm running into a bump in the road here and i'm not all to familiar with javascript. Basically what i'm trying to do is to show some input fields and labels based on a value that i'm passing from a database. if the value equals a 1 or a 2, then the fields display. Here is what i have so far: >function PageLoad(equicell) { document.forms[0].elements[0].focus(); //alert(equicell); if (equicell == '1' || equicell == '2') { document.formAcceptanceFull.current_Physical_street_address.visible = true; document.formAcceptanceFull.current_Physical_street_address2.visible = true; document.formAcceptanceFull.current_Physical_city.visible = true; document.formAcceptanceFull.current_Physical_state.visible = true; document.formAcceptanceFull.current_Physical_zip_code.visible = true; document.formAcceptanceFull.current_Physical_plus_4.visible = true; document.formAcceptanceFull.current_Physical_street_address_label.visible = true; document.formAcceptanceFull.current_Physical_street_address2_label.visible = true; document.formAcceptanceFull.current_Physical_city_label.visible = true; document.formAcceptanceFull.current_Physical_state_label.visible = true; document.formAcceptanceFull.current_Physical_zip_code_label.visible = true; document.formAcceptanceFull.current_Physical_plus_4_label.visible = true; document.formAcceptanceFull.current_Physical_street_address.value = ""; document.formAcceptanceFull.current_Physical_street_address2.value = ""; document.formAcceptanceFull.current_Physical_city.value = ""; document.formAcceptanceFull.current_Physical_state.value = ""; document.formAcceptanceFull.current_Physical_zip_code.value = ""; document.formAcceptanceFull.current_Physical_plus_4.value = ""; } } I have ID tags around all non-input fields that end in "_label" (in the html). I keep getting an error saying: >Error: document.formAcceptanceFull.current_Physical_street_address_label has no properties What am i doing wrong?? any help would be greatly appreciated. Thanks! -Sam Quote
HCSuperStores Posted February 21, 2005 Posted February 21, 2005 I can probably help you, but not without the HTML to go with it. Paste that in there too! Thnx, Bill H Quote
samporras Posted February 21, 2005 Author Posted February 21, 2005 i'll paste the snippets of html that apply to this (it's a very long page) anyways here it is: function PageLoad(equicell) { document.forms[0].elements[0].focus(); //alert(equicell); if (equicell == '1' || equicell == '2') { document.formAcceptanceFull.current_Physical_street_address.visible = true; document.formAcceptanceFull.current_Physical_street_address2.visible = true; document.formAcceptanceFull.current_Physical_city.visible = true; document.formAcceptanceFull.current_Physical_state.visible = true; document.formAcceptanceFull.current_Physical_zip_code.visible = true; document.formAcceptanceFull.current_Physical_plus_4.visible = true; document.formAcceptanceFull.current_Physical_street_address_label.visible = true; document.formAcceptanceFull.current_Physical_street_address2_label.visible = true; document.formAcceptanceFull.current_Physical_city_label.visible = true; document.formAcceptanceFull.current_Physical_state_label.visible = true; document.formAcceptanceFull.current_Physical_zip_code_label.visible = true; document.formAcceptanceFull.current_Physical_plus_4_label.visible = true; document.formAcceptanceFull.current_Physical_street_address.value = ""; document.formAcceptanceFull.current_Physical_street_address2.value = ""; document.formAcceptanceFull.current_Physical_city.value = ""; document.formAcceptanceFull.current_Physical_state.value = ""; document.formAcceptanceFull.current_Physical_zip_code.value = ""; document.formAcceptanceFull.current_Physical_plus_4.value = ""; } } function OnStateChanged() { if (document.formAcceptanceFull.radiobuttonYES.value == "radiobuttonYES") { document.formAcceptanceFull.current_Physical_street_address.visible = true; document.formAcceptanceFull.current_Physical_street_address2.visible = true; document.formAcceptanceFull.current_Physical_city.visible = true; document.formAcceptanceFull.current_Physical_state.visible = true; document.formAcceptanceFull.current_Physical_zip_code.visible = true; document.formAcceptanceFull.current_Physical_plus_4.visible = true; document.formAcceptanceFull.current_Physical_street_address_label.visible = true; document.formAcceptanceFull.current_Physical_street_address2_label.visible = true; document.formAcceptanceFull.current_Physical_city_label.visible = true; document.formAcceptanceFull.current_Physical_state_label.visible = true; document.formAcceptanceFull.current_Physical_zip_code_label.visible = true; document.formAcceptanceFull.current_Physical_plus_4_label.visible = true; document.formAcceptanceFull.current_Physical_street_address.value = ""; document.formAcceptanceFull.current_Physical_street_address2.value = ""; document.formAcceptanceFull.current_Physical_city.value = ""; document.formAcceptanceFull.current_Physical_state.value = ""; document.formAcceptanceFull.current_Physical_zip_code.value = ""; document.formAcceptanceFull.current_Physical_plus_4.value = ""; } else { document.formAcceptanceFull.current_Physical_street_address.visible = false; document.formAcceptanceFull.current_Physical_street_address2.visible = false; document.formAcceptanceFull.current_Physical_city.visible = false; document.formAcceptanceFull.current_Physical_state.visible = false; document.formAcceptanceFull.current_Physical_zip_code.visible = false; document.formAcceptanceFull.current_Physical_plus_4.visible = false; } } <body bgcolor="#FFFFFF" marginheight="0" marginwidth="0" topmargin="0" leftmargin="0" onload="PageLoad('<%=Mid(cDataHolder.Mail_Equicell,2,1)%>')">[b]<table border="0" cellspacing="0" summary="layout table"><tbody><form id="formAcceptanceFull" name="formAcceptanceFull" action="acceptanceFull.asp" method="POST">[/b]<tr valign="baseline"> <td align="right" class="standard-font"><p class="paragraph_nomargin"><strong>Is your mailing address the same as <br> your physical address?</strong></p></td> <td> </td> <td class="standard-font"><br> <input name="radiobuttonYES" type="radio" value="radiobuttonYES" checked> Yes<br> <input name="radiobuttonNO" type="radio" value="radiobuttonNO"> No</td> </tr> <tr valign="top"> <td colspan="3" align="right" class="standard-font"><img src="../images/pixel.gif" alt="" width="545" height="10" border="0"></td> </tr> <tr valign="top" bgcolor="#00FF00"> <td colspan="3"> <table width="100%" border="0" cellpadding="0" cellspacing="0" bgcolor="#E9E9EA"> <tr> <td width="5"> </td> <td class="standard-font"><p class="paragraph_nomargin"><strong>P</strong><img height="20" alt="" src="../images/pixel.gif" width="5" border="0"><strong>hysical Street Address:</strong></p></td> </tr> </table></td> </tr> <tr valign="top"> <td colspan="3" align="right" class="standard-font"><img src="../images/pixel.gif" alt="" width="545" height="10" border="0"></td> </tr> <tr valign="top"> <td align="right" valign="bottom" class="standard-font"><p class="paragraph_nomargin"><font color="<%=strColorPhysicalAddress%>"><strong><label for="current_Physical_street_address" id="current_Physical_street_address_label">*Address 1:</label></strong><br> (no P.O. Boxes)</font></p></td> <td> </td> <td align="left"><input type=text maxlength="30" name="current_Physical_street_address" id="current_Physical_street_address" size="30" value="<%=cDataHolder.Web_Physical_Address1%>"> </td> </tr> <tr valign="top"> <td colspan="3" align="right" class="standard-font"><img src="../images/pixel.gif" alt="" width="545" height="10" border="0"></td> </tr> <tr valign="top"> <td align="right" valign="bottom" class="standard-font"><p class="paragraph_nomargin"><font color="<%=strColorPhysicalAddress2%>"><strong><label for="current_Physical_street_address2" id="current_Physical_street_address2_label"> Address 2:</label></strong></font></p></td> <td> </td> <td align="left"><input maxlength="20" name="current_Physical_street_address2" id="current_Physical_street_address2" size="24" value="<%=cDataHolder.Web_Physical_Address2%>"> </td> </tr> <tr valign="top"> <td colspan="3" align="right" class="standard-font"><img src="../images/pixel.gif" alt="" width="545" height="10" border="0"></td> </tr> <tr valign="baseline"> <td align="right" class="standard-font"><p class="paragraph_nomargin"><font color="<%=strColorPhysicalCity%>"><strong><label for="current_Physical_city" id="current_Physical_city_label"> *City:</label></strong></font></p></td> <td> </td> <td align="left"><input maxlength="15" name="current_Physical_city" id="current_Physical_city" size="15" value="<%=cDataHolder.Web_Physical_City%>"> </td> </tr> <tr valign="top"> <td colspan="3" align="right" class="standard-font"><img src="../images/pixel.gif" alt="" width="545" height="10" border="0"></td> </tr> <tr valign="baseline"> <td align="right" class="standard-font"><p class="paragraph_nomargin"><font color="<%=strColorPhysicalState%>"><strong><label for="current_Physical_state" id="current_Physical_state_label"> *State:</label></strong></font></p></td> <td> </td> <td align="left"> <select name="current_Physical_state" id="current_Physical_state" size="1"> <% FOR i=1 to state_array_length %> <% if Trim(CStr(cDataHolder.Web_Physical_State)) = "" then %> <% Response.Write("<OPTION VALUE=" & state_array(i,1) & "><FONT face=" & Application("DefaultFONT") & " SIZE=3>" & state_array(i,2) & "</FONT>") %> <% else %> <% if (state_array(i,1) = Trim(CStr(cDataHolder.Web_Physical_State))) then %> <% Response.Write("<OPTION SELECTED VALUE=" & state_array(i,1) & "><FONT face=" & Application("DefaultFONT") & " SIZE=3>" & state_array(i,2) & "</FONT>") %> <% else %> <% Response.Write("<OPTION VALUE=" & state_array(i,1) & "><FONT face=" & Application("DefaultFONT") & " SIZE=3>" & state_array(i,2) & "</FONT>") %> <% end if %> <% end if %> <% NEXT %> </select> </td> </tr> <tr valign="top"> <td colspan="3" align="right" class="standard-font"><img src="../images/pixel.gif" alt="" width="545" height="10" border="0"></td> </tr> <tr valign="baseline"> <td align="right" class="standard-font"><p class="paragraph_nomargin"><font color="<%=strColorPhysicalZip%>"><strong><label for="current_Physical_zip_code" id="current_Physical_zip_code_label"> *Zip Code:</label></strong></font></p></td> <td> </td> <td class="standard-font"> <input maxlength="5" name="current_Physical_zip_code" id="current_Physical_zip_code" size="5" value="<%=cDataHolder.Web_Physical_Zip_Code%>"> - <input maxlength="4" name="current_Physical_plus_4" id="current_Physical_plus_4" size="4" value="<%=cDataHolder.Web_Physical_Zip_Code4%>"> </td> </tr>[b]</tbody></table>[/[/b]code] Quote
borfast Posted February 21, 2005 Posted February 21, 2005 There's no "formAcceptanceFull" element in your HTML, so JavaScript obviously can't access any properties of an element it doesn't know and doesn't even exist Quote
HCSuperStores Posted February 21, 2005 Posted February 21, 2005 HHhhhmmm ... This might take a couple of steps ... I'm not used to coding in the way you have. Usually my HTML will looking something like this: ><form name="myform"> <input name="myelement1" .... > <input name="myelement2" .... > </form> . . . <script ... > document.myform.myelement1.visable=true; myvalue = document.myform.myelement1.value; . . . </script> I've never accessed properties of form elements without at least using a form tag that has a form name. Then, each element having its own name so you can access the elements through the form object, or by document.forms[0].elements[0].value if you want to leave out the form and element names. Does that make any sense? Quote
samporras Posted February 22, 2005 Author Posted February 22, 2005 sorry i didn't get back to you guys. Here's what I came up with (with some help from my co-workers)...i'm using some java script to toggle off between showing the physical address fields. let me know what you guys think. ><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML><HEAD> <META http-equiv=Content-Type content="text/html; charset=windows-1252"> <META content="MSHTML 6.00.2800.1458" name=GENERATOR></HEAD> <BODY> <TABLE cellSpacing=0 cellPadding=0 width=400 border=0><NOSCRIPT> <TBODY> <TR> <TD> <H3>ADA Compliant</H3></TD></TR></NOSCRIPT> <TR id=TR_01 style="DISPLAY: none"> <TD>An asterisk (*) indicates a required field.</TD></TR> <TR> <TD align=left> <TABLE cellSpacing=0 cellPadding=2 width=400 border=0> <TBODY> <TR> <TD colSpan=2> </TD></TR> <TR> <TD style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; PADDING-BOTTOM: 0px; PADDING-TOP: 0px" bgColor=#c0c0c0 colSpan=2> <STRONG>Physical Address</STRONG></TD></TR> <TR> <TD colSpan=2> </TD></TR> <TR> <TD vAlign=top noWrap align=right width=200><STRONG>* Address: </STRONG></TD> <TD vAlign=bottom align=left width=200><INPUT></TD></TR> <TR> <TD vAlign=top noWrap align=right width=200><STRONG>* City: </STRONG></TD> <TD vAlign=bottom align=left width=200><INPUT size=10></TD></TR> <TR> <TD vAlign=top noWrap align=right width=200><STRONG>* State: </STRONG></TD> <TD vAlign=bottom align=left width=200><INPUT size=2></TD></TR> <TR> <TD vAlign=top noWrap align=right width=200><STRONG>* Zip Code: </STRONG></TD> <TD vAlign=bottom align=left width=200><INPUT size=5></TD></TR></TBODY></TABLE></TD></TR> <TR id=TR_02 style="DISPLAY: none"> <TD align=left> <TABLE cellSpacing=0 cellPadding=2 width=400 border=0> <TBODY> <TR> <TD colSpan=2> </TD></TR> <TR> <TD style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; PADDING-BOTTOM: 0px; PADDING-TOP: 0px" bgColor=#c0c0c0 colSpan=2> <STRONG>Mailing Address</STRONG></TD></TR> <TR> <TD vAlign=top align=right width=200><BR><STRONG>* Is your mailing address the same as your physical address?</STRONG></TD> <TD vAlign=bottom align=left width=200><INPUT onclick="if(document.layers){TR_03.style.visibility='hide';}else{TR_03.style.display='none';}" type=radio CHECKED name=mailing_eq_physical>Yes</TD></TR> <TR> <TD vAlign=top align=right width=200> </TD> <TD vAlign=bottom align=left width=200><INPUT onclick="if(document.layers){TR_03.style.visibility='show';}else{TR_03.style.display='inline';}" type=radio name=mailing_eq_physical>No</TD></TR></TBODY></TABLE></TD></TR> <TR id=TR_03> <TD align=left> <TABLE cellSpacing=0 cellPadding=2 width=400 border=0><NOSCRIPT> <TBODY> <TR> <TD colSpan=2> </TD></TR> <TR> <TD bgColor=#c0c0c0 colSpan=2> <STRONG>Mailing Address</STRONG></TD></TR></NOSCRIPT> <TR> <TD align=left width=400 colSpan=2><BR><STRONG>Please provide your mailing address<NOSCRIPT> if it differs from your physical address</NOSCRIPT>.</STRONG></TD></TR> <TR> <TD colSpan=2> </TD></TR> <TR> <TD vAlign=top noWrap align=right width=200><STRONG><SPAN id=SP_01 style="DISPLAY: none">*</SPAN> Address: </STRONG></TD> <TD vAlign=bottom align=left width=200><INPUT></TD></TR> <TR> <TD vAlign=top noWrap align=right width=200><STRONG><SPAN id=SP_02 style="DISPLAY: none">*</SPAN> City: </STRONG></TD> <TD vAlign=bottom align=left width=200><INPUT size=10></TD></TR> <TR> <TD vAlign=top noWrap align=right width=200><STRONG><SPAN id=SP_03 style="DISPLAY: none">*</SPAN> State: </STRONG></TD> <TD vAlign=bottom align=left width=200><INPUT size=2></TD></TR> <TR> <TD vAlign=top noWrap align=right width=200><STRONG><SPAN id=SP_04 style="DISPLAY: none">*</SPAN> Zip Code: </STRONG></TD> <TD vAlign=bottom align=left width=200><INPUT size=5></TD></TR></TBODY></TABLE></TD></TR> <script language=JavaScript> if(document.layers){ TR_01.style.visibility='show'; TR_02.style.visibility='show'; TR_03.style.visibility='hide'; }else{ TR_01.style.display='block'; TR_02.style.display='block'; TR_03.style.display='none'; } for(i=1;i<5;i++){ if(document.layers){document.all('SP_0'+i).style.visibility='show';}else{document.all('SP_0'+i).style.display='inline';} } </SCRIPT> </TBODY></TABLE></BODY></HTML> This works well in my browser (the most recent version of IE), but i noticed that does not work well in netscape or firefox.....any suggestions? -Sam Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.