Object has no properties error
Posted: Thu Apr 26, 2007 12:47 pm
Hi
This has been driving me crazy - I'm not a JS expert, but I've given this days, it works - but it's generating errors.
It's a simple show/hide function that I'm trying to execute in a loop.
One item of 6 gets revealed, and the others get hidden.
How do I get rid of that one error on the "else" statement?
and the HTML;
This has been driving me crazy - I'm not a JS expert, but I've given this days, it works - but it's generating errors.
It's a simple show/hide function that I'm trying to execute in a loop.
One item of 6 gets revealed, and the others get hidden.
How do I get rid of that one error on the "else" statement?
Code: Select all
function OrderDuration(id) {
var dispItem = document.getElementById(id).value
var myTypes = new Array(6)
myTypes[0] = 'CD01'
myTypes[1] = 'CD02'
myTypes[2] = 'CD03'
myTypes[3] = 'CD04'
myTypes[4] = 'CD05'
myTypes[5] = 'CD10'
for (i=0;i<=6; i++ )
{
var changeThis = document.getElementById(myTypes[i])
if(dispItem == myTypes[i])
{
changeThis.style.display = ""
}
else
{
changeThis.style.display = "none" // error here: changeThis has no properties
}
}
}
Code: Select all
<body>
<select name="quantity" id="quantity" onchange="OrderDuration('quantity');">
<option selected="selected" value="" >Select quantity</option>
<option value="CD01" >Just the 1 </option>
<option value="CD02" >+ 1 </option>
<option value="CD03" >+ 2 </option>
<option value="CD04" >+ 3 </option>
<option value="CD05" >+ 4 </option>
<option value="CD10" >+ 10 </option>
</select>
<select name="duration[]" id="CD01" style="display:none" >
<option selected="selected" value="" >Select duration - CD01</option>
<option value="3" >3 Months ( £36 - Save £0)</option>
<option value="6" >6 Months ( £68.4 - Save £3.6)</option>
<option value="12" >12 Months ( £129.6 - Save £14.4)</option>
</select>
<select name="duration[]" id="CD02" style="display:none" >
<option selected="selected" value="" >Select duration - CD02</option>
<option value="3" >3 Months ( £72 - Save £0)</option>
<option value="6" >6 Months ( £136.8 - Save £7.2)</option>
<option value="12" >12 Months ( £259.2 - Save £28.8)</option>
</select>
<select name="duration[]" id="CD03" style="display:none" >
<option selected="selected" value="" >Select duration - CD03</option>
<option value="3" >3 Months ( £108 - Save £0)</option>
<option value="6" >6 Months ( £205.2 - Save £10.8)</option>
<option value="12" >12 Months ( £388.8 - Save £43.2)</option>
</select>
<select name="duration[]" id="CD04" style="display:none" >
<option selected="selected" value="" >Select duration - CD04</option>
<option value="3" >3 Months ( £144 - Save £0)</option>
<option value="6" >6 Months ( £273.6 - Save £14.4)</option>
<option value="12" >12 Months ( £518.4 - Save £57.6)</option>
</select>
<select name="duration[]" id="CD05" style="display:none" >
<option selected="selected" value="" >Select duration - CD05</option>
<option value="3" >3 Months ( £180 - Save £0)</option>
<option value="6" >6 Months ( £342 - Save £18)</option>
<option value="12" >12 Months ( £648 - Save £72)</option>
</select>
<select name="duration[]" id="CD10" style="display:none" >
<option selected="selected" value="" >Select duration - CD10</option>
<option value="3" >3 Months ( £360 - Save £0)</option>
<option value="6" >6 Months ( £684 - Save £36)</option>
<option value="12" >12 Months ( £1296 - Save £144)</option>
</select>
</body>