PDA

View Full Version : code not working in firefox



aqeel
03-18-2011, 09:29 PM
hi fellows im totaly new to javascript , i wrote the following code which is working with IE8 but not with firefox 3.6 any could plz help me
<script type="text/javascript">
function calculate(field){
var salePrice = document.testForm.price.value;
var discount = testForm.discnt.options[testForm.discnt.selectedIndex].value;
var amount = salePrice * discount/100;
document.testForm.total.value = amount;
}
</script>

<form name="testForm" id="testForm">
<input type="text" name="price" id="price" value="0" onchange="calculate(this);" />
<select name="discnt" id="discnt" onchange="calculate(this);">
<option value="10">10%</option>
<option value="20">20%</option>
<option value="30">30%</option>
</select>
<input type="text" name="total" id="total" value="0" />
</form>

jscheuer1
03-19-2011, 08:03 AM
Pretty non-standard, so I'll just make it work rather than get into the business of 'how it should be':


function calculate(field){
var salePrice = document.testForm.price.value;
var discount = document.testForm.discnt.options[document.testForm.discnt.selectedIndex].value;
var amount = salePrice * discount/100;
document.testForm.total.value = amount;
}