I have a function
function setbid(catid)
{
if(catid == 30)
{
document.getElementById('bannerid').value = 1;
}
else if(catid == 31){
document.getElementById('bannerid').value = 2;
}
else if(catid == 32){
document.getElementById('bannerid').value = 6;
}
}
this function is being called onchange event of select box.
now when the value of select box is changed IE throws me an error saying
"document.getElementId(....)" is null or not an object..
Now what can i infer from this?
please help..
UPDATE
As per David's Reply how can i check for its existance before the assignment of value to that field,? Also other browsers do not display this error, I have this bannerid field as hidden field in the document... What should be done?
Below is the screen shot of the error displayed onchange of select box
Update 2 Update as per the answer of @haylem
<script>
function setbid(catid)
{
var lookup = {
'30' : 1,
'31' : 2,
'32' : 6
};
if (lookup.hasOwnProperty(catid)) {
var el = document.getElementById('bannerid');
if (el) {
el.value = lookup[catid];
}
}
/*if(catid == 30)
{
if(typeof(document.getElementById('bannerid')) == null ){
document.getElementById('bannerid').value = 1;
}
}
else if(catid == 31){
document.getElementById('bannerid').value = 2;
}
else if(catid == 32){
document.getElementById('bannerid').value = 6;
}*/
}
</script>
<div style="margin:0px auto">
<div class="instantprice-popup-bg">
<form name="instantpop" id="instantpop" action="" method="post" style="margin:0px; padding:0px" onsubmit="">
<input type="hidden" name="sessid" id="sessid" value="<?php echo $_GET['osCsid'];?>">
<div class="instantprice">
<ul>
<li class="text12pt" style="color:#FF0000; display:none;" id="appsize">For special low price on sizes over 30ft. wide and 10ft. height contact us on [email protected].</li>
<li class="text12pt" style="color:#FF0000; display:none;" id="vinylsize">Please enter width upto 30 ft & height upto 5 ft for Vinyl Signs/Decals(Posters).</li>
<li class="col1">Select Product</li>
<li class="col2">
<input type="hidden" name="price" id="price" value="<?php echo "15"; ?>" />
<input type="hidden" name="bannerid" id="bannerid" value="" />
<select name="product" class="dropdownfield" id="product" style="width: 180px;" onchange="javascript:setbid(document.getElementById('product').value);">
<option value="">Select Product</option>
<?php
while($result=mysql_fetch_object($sql_query))
{
?><option value="<?php echo $result->categories_id;?>" <?php if($_POST['product'] == $result->categories_id) {?> selected="selected" <?php } ?>><?php echo $result->categories_name;?></option><?php
}
?>
</select>
</li>
<li class="col1">Select Size (in ft.)</li>
<li class="col2">
<div class="sizebox" style="width:250px;">
<div class="sizebox col1"><input name="size_w" id="size_w" type="text" class="sizetextfield1" value="<?php if(isset($_REQUEST['size_w'])){ echo $_REQUEST['size_w']; } else { echo "2"; } ?>" ></div>
<div class="sizebox col2"><img src="images/homepage/up-arrow.jpg" width="12" height="9" border="0" align="top" onclick="increaseCounter('size_w')" /><img src="images/homepage/down-arrow.jpg" width="12" height="9" border="0" onclick="decreaseCounter('size_w');" /></div>
<div class="sizebox col3" style="width:35px;">width</div>
<div class="sizebox col1"><input name="size_h" id="size_h" type="text" class="sizetextfield1" value="<?php if(isset($_REQUEST['size_h'])){ echo $_REQUEST['size_h']; } else { echo "2"; } ?>" style="margin-left:8px" ></div>
<div class="sizebox col2"><img src="images/homepage/up-arrow.jpg" width="12" height="9" border="0" align="top" onclick="increaseCounter('size_h');" /><img src="images/homepage/down-arrow.jpg" width="12" height="9" border="0" onclick="decreaseCounter('size_h');" /></div>
<div class="sizebox col3" style="width:35px;"> height</div>
<input name="size" id="size" type="hidden" value="<?php echo $_REQUEST['size_h'].'x'.$_REQUEST['size_w']; ?>">
</div>
</li>
<li class="col1">Select Quantity</li>
<li class="col2">
<select id="qty" name="qty" >
<?php
for($i=1;$i<=100;$i++)
{
?> <option value="<?php echo $i;?>" <?php if($_POST['qty'] == $i) {?> selected="selected" <?php } ?>><?php echo $i;?></option> <?php
}
?>
</select>
</li>
<li class="col1">Select Shipping</li>
<li class="col2">
<select id="shipping_method" name="shipping_method" class="dropdownfield" >
<option value="">Select Shipping</option>
<option value="standard" <?php if($_POST['shipping_method'] == 'standard') {?> selected="selected" <?php } ?>>Standard (7 - 12 days from proof)</option>
<option value="expedited"<?php if($_POST['shipping_method'] == 'expedited') {?> selected="selected" <?php } ?>>Expedited (5 work days from Proof)</option>
</select>
</li>
<li class="col1" id="sidehead">Two Side Banner</li>
<li class="col2" id="sideval">
<input type="checkbox" id="side" name="side" value="1" />
</li>
<li class="col1">Product Price</li>
<li class="col2"><span class="text15pt" id="total_display">$0</span>
<input type="hidden" id="total" name="total" class="textfield" value="15" readonly="readonly" style="width:60px;"/>
</li>
<li class="col1">Shipping Cost</li>
<li class="col2"><span class="text15pt" id="shipping_display">$0</span>
<input type="hidden" id="shipping" name="shipping" class="textfield" value="" readonly="readonly" style="width:60px;" />
</li>
<li class="bannerprice" id="grand_total_display">TOTAL PRICE : $0
</li><input type="hidden" id="grand_total" name="grand_total" value="" readonly="readonly" style="width:60px;" />
<li style="float:none; text-align:center">
<input type="submit" class="getprice-btn" name="getprice" value="" />
</li>
<li class="text12pt">Final Price, No Hidden Charges</li>
</ul>
<input type="hidden" name="getpriceclick" value="1" />
</div>
</form>
</div>
</div>