rdnobel123
Programmer
Hello,
I got stuck on a problem with Javascript in Firefox. It works in IE but not in Firefox.
I have two SELECT lists on my page, one is called “Provincie” and the other “Regio”.
When the Provincie SELECT is changed, the Regio SELECT will display only the Regios which are in the selected Provincie.
To accomplish this I did the following :
- Place 2 SELECT boxes on the page (Provincie and Regio)
- Add an onChange to the Provincie SELECT which refers to a javascript function SubCat()
- The SubCat() javascript empties the Regio SELECT and fills it with the right OPTIONS depending on the selected OPTION in the Provincie SELECT.
The code is actually a lot longer, but because I use a server side script to generate the repeating block (if ( x.value == "<int>" ){ // code }) ,I only posted 3 if blocks which are enough to illustrate how the script works.
The javascript console in Firefox gives me a whole list of the following :
Error : y has no properties
Source : <here it mentions the source file>
Clicking on the link gives me statements like the following :
y.options.length = 0
It also mentions this for the variables :
* temp
* document.getelementbyid(“front_zoek_trefwoord”)
It seems to me that I’m doing something completely wrong but I can’t figure out what.
Does anyone know how to fix this problem ?
I would appreciate any help, as I am totally stuck.
Regards,
Rens de Nobel
THE CODE :
I got stuck on a problem with Javascript in Firefox. It works in IE but not in Firefox.
I have two SELECT lists on my page, one is called “Provincie” and the other “Regio”.
When the Provincie SELECT is changed, the Regio SELECT will display only the Regios which are in the selected Provincie.
To accomplish this I did the following :
- Place 2 SELECT boxes on the page (Provincie and Regio)
- Add an onChange to the Provincie SELECT which refers to a javascript function SubCat()
- The SubCat() javascript empties the Regio SELECT and fills it with the right OPTIONS depending on the selected OPTION in the Provincie SELECT.
The code is actually a lot longer, but because I use a server side script to generate the repeating block (if ( x.value == "<int>" ){ // code }) ,I only posted 3 if blocks which are enough to illustrate how the script works.
The javascript console in Firefox gives me a whole list of the following :
Error : y has no properties
Source : <here it mentions the source file>
Clicking on the link gives me statements like the following :
y.options.length = 0
It also mentions this for the variables :
* temp
* document.getelementbyid(“front_zoek_trefwoord”)
It seems to me that I’m doing something completely wrong but I can’t figure out what.
Does anyone know how to fix this problem ?
I would appreciate any help, as I am totally stuck.
Regards,
Rens de Nobel
THE CODE :
Code:
<script type="text/javascript">
function SubCat()
{
// Get the PROVINCIE SELECT and REGIO SELECT
// Contents of the REGIO SELECT LIST is dependent on the
// selection in the PROVINCIE SELECT LIST
var x=document.getElementById('front_zoek_provincieID');
var temp=document.getElementById('front_zoek_regioID');
// Clear the REGIO SELECT LIST and add the “Alle regios” element
// to search on all regios
temp.options.length = 0;
temp.add(document.createElement('OPTION'));
temp.options[0].text="Alle regios";
temp.options[0].value="";
// If provincieID = 1 then add all regios which belong to this provincie
// to the REGIO SELECT LIST
if ( x.value == "1" )
{
var y=document.getElementById('front_zoek_regioID')
y.options.length = 1
y.add(document.createElement('OPTION'))
y.options[1].text="Drenthe"
y.options[1].value="14"
};
if ( x.value == "6" )
{
var y=document.getElementById('front_zoek_regioID')
y.options.length = 1
y.add(document.createElement('OPTION'))
y.options[1].text="Limburg-Zuid"
y.options[1].value="20"
y.add(document.createElement('OPTION'))
y.options[2].text="Limburg-Noord"
y.options[2].value="21"
};
if ( x.value == "7" )
{
var y=document.getElementById('front_zoek_regioID')
y.options.length = 1
y.add(document.createElement('OPTION'))
y.options[1].text="Midden & West Brabant"
y.options[1].value="23"
y.add(document.createElement('OPTION'))
y.options[2].text="Brabant Zuid-Oost"
y.options[2].value="27"
y.add(document.createElement('OPTION'))
y.options[3].text="Brabant Noord"
y.options[3].value="28"
};
}
</script>
<select style='width:100px;' id="front_zoek_provincieID" onchange="SubCat()" NAME="front_zoek_provincieID">
<option value='1'>Drenthe </option>
<option value='2'>Flevoland </option>
<option value='3'>Friesland </option>
<option value='4'>Gelderland </option>
<option value='5'>Groningen </option>
<option value='6'>Limburg </option>
<option value='7'>Noord-Brabant </option>
<option value='8'>Noord-Holland </option>
<option value='9'>Overijssel </option>
<option value='10'>Utrecht </option>
<option value='11'>Zeeland </option>
<option value='12'>Zuid-Holland </option>
</select>
<select style='width:100px;' id="SubCategorie" NAME="front_zoek_regioID">
</select>
<script language=javascript>
SubCat(); // also fill the regio SELECT when loading the page
</script>