Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

firefox error 2

Status
Not open for further replies.

leahyj

MIS
May 5, 2004
107
US
I get a "document.getElementById("CountyList") has no properties" error message in the JavaScript Console in Fire Fox.

line error in function:
Code:
document.getElementById('CountyList').options.length = 0;


entire function:
Code:
function State_Select()
{

ind = document.forms['payoff_regionsearch'].elements['StateList'].selectedIndex;
val = document.forms['payoff_regionsearch'].elements['StateList'].options[ind].value;


if (ind == 0)
{
alert('Select a valid State.')

//clearlist();

//var i;

//for (i = document.payoff_regionsearch.CountyList.options.length - 1; i >= 1; i--){
//	document.payoff_regionsearch.CountyList.options[i] = null;
//	}
	
//document.payoff_regionseach.CountyList.selectedIndex = 0;
document.forms['payoff_regionsearch'].submit();
document.forms['payoff_liensearch'].elements['PropOwnName'].text = "";
document.forms['payoff_liensearch'].elements['PropFolioNum'].text = "";
document.forms['payoff_liensearch'].elements['PropAddress'].text = "";

document.forms['payoff_regionsearch'].elements['CountyList'].disabled=true;
document.forms['payoff_liensearch'].elements['PropOwnName'].disabled=true;
document.forms['payoff_liensearch'].elements['PropFolioNum'].disabled=true;
document.forms['payoff_liensearch'].elements['PropAddress'].disabled=true;
} 
else 
{
[b]
document.getElementById('CountyList').options.length = 0;[/b]
document.forms['payoff_regionsearch'].submit();
document.forms['payoff_regionsearch'].elements['CountyList'].disabled=false;
document.forms['payoff_liensearch'].elements['PropOwnName'].disabled=false;
document.forms['payoff_liensearch'].elements['PropFolioNum'].disabled=false;
document.forms['payoff_liensearch'].elements['PropAddress'].disabled=false;
}
return 0;}


thanks to all
 
going to lunch, will get back to you on that

Thanks a bunch
 
Here is a fix to your kind of problem:
Code:
var countryList = document.getElementById('CountyList');
if (countryList) {
  if (countryList.options){
    countryList.options.length = 0;
  }
}
You just need to be a little robust in checking stuff.

Cheers,
Jeff

[tt]Jeff's Page @ Code Couch
[/tt]

What is Javascript? FAQ216-6094
 
I'd guess that there's an element with the name CountyList, but not with an id CountyList.

Lee
 
Lunch was good, thanks. Wendy's!

Anyway, I tried BabyJeffy's code and it got rid of the error. Thanks

The new problem is that it isn't behaving in Firefox the way it should and or the way it behaves in Internet Explorer. In other words, it works in Internet Explorer the way I want it to.

The problem:

I have two dropdown lists one that effects the other and when I choose a state from the first dropdown and then a county from the other and then choose a state again without submitting the form, the result list comes back empty because it is still referencing the old county from the previous state.

So in Internet Explorer, I am able to clear the list with the
Code:
countylist.options.length = 0
code, but not in firefox.

Thanks.
 
how did I know you'd opt for the cover-up solution, rather than actually determining what the cause of the problem was? you didn't answer any of the questions i posed to you, nor did you respond to Dan's nor Lee's.



*cLFlaVA
----------------------------
[tt]"quote goes here"[/tt]
[URL unfurl="true"]http://www.coryarthus.com/[/url]
 
Hey cLFlaVA, you've helped me out in the past. I didn't mean to skip over you.

Here is the html:
Code:
<fieldset>
<legend>
Search Form
</Legend>

<form name="payoff_regionsearch" method="POST" action="online_payoff_search.asp">

<table width="100%" border="0" cellspacing="0" cellpadding="3">
<tr>
<td width="50%" align="right"><font size="2">Please select a state first:</font></td>
<td width="20%" align="left" valign="top" <font size="2">
<%

On Error Resume Next
set dbconn1 = Server.CreateObject("ADODB.Connection")
dbconn1.Open pgconn
set rsStates = Server.CreateObject("ADODB.Recordset")
strSql= "SELECT statecode, statename FROM live.adminState ORDER BY statecode"
rsStates.Open strSql, dbconn1
%>
<select name="StateList" Language="Javascript" onchange="return State_Select();">
<option selected>Select State</option>
<%

While not rsStates.EOF
code=rsStates.Fields("StateCode")
name=rsStates.Fields("StateName")
%>
<option value="<%Response.Write(code)%>"
<%
If Request.Form("StateList") = code Then Response.Write " selected"
Response.Write "> " & name & "</option>"
rsStates.MoveNext()
Wend
rsStates.Close
dbconn1.close
%>
</select>
</font>
</td>
<td width="20%" align="right" valign="top" <font size="2">
<%
strSql = ""
On Error Resume Next
set dbconn1 = Server.CreateObject("ADODB.Connection")
dbconn1.Open pgconn
set rsCounties = Server.CreateObject("ADODB.Recordset")
strSql= "SELECT countycode, countyname FROM live.admincounty WHERE countystatecode = '" & Request.Form("StateList") & "' ORDER BY countyname"
rsCounties.Open strSql, dbconn1
%>
<select name="CountyList" Language="Javascript" onchange="return County_Select();">
<option selected>Select County</option>
<%
While not rsCounties.EOF
code=rsCounties.Fields("countycode")
name=rsCounties.Fields("countyname")
%>
<option value="<%Response.Write(code)%>"
<%
If (Request.Form("CountyList") = code And Request.Form("StateList") <> "Select State") Then Response.Write " selected"
Response.Write "> " & name & "</option>"
rsCounties.MoveNext()
Wend
rsCounties.Close
dbconn1.close
%>
</select>
</font>
</td>
</table>
</form>

<form name="payoff_liensearch" method="post" action="online_payoff_results.asp">
<hr>
<br>
<table width="100%" border="0" cellspacing="0" cellpadding="3">
</tr>
<tr>
<td width="40%" align="right"><font size="2">Owner Last Name:</font></td>
<td width="15%"><font size="2" face="Arial">
<input type="text" name="PropOwnName"
<%
If Request.Form("StateList") = "" Or Request.Form("StateList") = "Select State" Then Response.Write " disabled=" & "'true'"
Response.Write " size=" & "'20'" & "></font></td>"
%>
<td width="30%"align="right"><font size="2">Parcel ID:</font></td>
<td width="15%"><font size="2">
<input type="text" name="PropFolioNum"
<%
If Request.Form("StateList") = "" Or Request.Form("StateList") = "Select State" Then Response.Write " disabled=" & "'true'"
Response.Write " size=" & "'20'" & "></font></td>"
%>
</tr>
<tr>
<td width="40%" align="right"><font size="2">Property Address:</font></td>
<td width="15%"><font size="2">
<input type="text" name="PropAddress"
<%
If Request.Form("StateList") = "" Or Request.Form("StateList") = "Select State" Then Response.Write " disabled=" & "'true'"
Response.Write " size=" & "'20'" & "></font></td>"
%>
<td width="30%" align="right">&nbsp;</td>
<td width="15%" align="center" valign="bottom"><input type="submit" value="Search for Lien"></td>
</tr>
</table>

<%
'response.write request.form("StateList")
'response.write request.form("CountyList")
st = request.form("StateList")
cty = request.form("CountyList")
If Request.Form("StateList") <> "Select State" Then Response.Write "<input type='" & "hidden' name='" & "PropState' size='" & "5' value='" & st & "'>"
If Request.Form("CountyList") <> "Select County" Then Response.Write "<input type='" & "hidden' name='" & "PropCnty' size='" & "5' value='" & cty & "'>"
%>
</form>

</fieldset>

question 2: yes, as you can see in the html.

question 3: yes, I believe the case is correct.

question 4: no, I don't believe I have two elements with that name.

question 5: yes, it is a dropdown/select-option list.

Thanks
 
thanks everyone:

I used

Code:
document.forms['payoff_regionsearch'].elements['CountyList'].options.length = 0;

instead of getElementByAnthing

 
you could also just as easily have changed your select element code to this:

Code:
<select name="CountyList" [red]id="CountyList" [/red] onchange="return County_Select();">



*cLFlaVA
----------------------------
[tt]"quote goes here"[/tt]
[URL unfurl="true"]http://www.coryarthus.com/[/url]
 
I thought something like that might work.

Thanks.
 
I have nothing better to do... so if you then extended your select to use an id... you could then use the label element. Here is how you might use a label element with your select:
Code:
<label for="[COLOR=red]CountryList[/color]">Choose your country</label>
<select name="CountyList" id="CountyList" onchange="return County_Select();">
<option>...</option>
</select>
This means that when you give the label focus (when you click on it) the focus moves immediately to the related form element (the select dropdown is focussed). The label can be in an entirely different part of the document as well.

It's one of these accessability things you may see more and more of.

Time to go and catalogue my stamp collection (by colour this time I think)...

Jeff

[tt]Jeff's Page @ Code Couch
[/tt]

What is Javascript? FAQ216-6094
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top