By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,700 Members | 1,458 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,700 IT Pros & Developers. It's quick & easy.

Onblur does not work

P: 8
Hi,

I have a javascript function that does a calculation and displays the result in the third function.The function is triggered by onblur function.It does not seem to work in IE nor Firefox.

Please help me.

[HTML]<script>
function probability()
{
var val1 = parseInt(document.getElementById('percentagego').v alue);
var val2 = parseInt(document.getElementById('percentagewin'). value);
var ansd = document.getElementById('probability');
ansd.value = Math.round((val1 * val2)/100);
}
</script>

<th class="bodyText" align="right">% Go:&nbsp;&nbsp;</th>
<td class="bodyText" colspan="2"><input type="text" id="percentagego" name="percentagego" value="<?php
if (!empty($percentagego)) {
echo number_format($percentagego,0);
}?>" maxlength="20" size="17"></td>
</tr>
<tr>
<th class="bodyText" align="right">% Win:&nbsp;&nbsp;</th>
<td class="bodyText" colspan="2"><input type="text" id="percentagewin" name="percentagewin" onBlur="probability()" value="<?php
if (!empty($percentagewin)) {
echo number_format($percentagewin,0);
}?>" maxlength="20" size="17"></td>
</tr>
<tr>
<th class="bodyText" align="right">Probability:&nbsp;&nbsp;</th>
<td class="bodyText" colspan="2"><input type="text" onBlur="probability()" name="probability" id="probability" value="" maxlength="3" size="5"></td>
</tr>[/HTML]
Jun 28 '07 #1
Share this Question
Share on Google+
3 Replies


P: 8
Hi,

This code works perfectly in IE but does not work in FireFox.

Also this function requires that the two values to be filled up to calculate the result or else it will display "NaN",How can i avoid displaying "NaN" is there any way i can display a alert saying two values are required?


Could someone please help me to resolve this.

[HTML]<script>
function probability0()
{
var val1 = parseInt(document.getElementById("ITEM_IN[0][PERCENTAGE_GO]").value);
var val2 = parseInt(document.getElementById("ITEM_IN[0][PERCENTAGE_WIN]").value);
var ansd = document.getElementById("ITEM_IN[0][PROBABILITY]");
ansd.value = Math.round((val1 * val2)/100);
}
</script>

<td class="bodyForm"><input type="text" name="ITEM_IN[0][PERCENTAGE_GO]" id="ITEM_IN[0][PERCENTAGE_GO]"maxlength="3" size="3" /></td>
<td class="bodyForm"><input type="text" onBlur="probability0()" name="ITEM_IN[0][PERCENTAGE_WIN]" id="ITEM_IN[0][PERCENTAGE_WIN]"maxlength="3" size="3"
/></td>

<td class="bodyForm">


<input type="text" id="answer" readonly="readonly" onBlur="probability0()" name="ITEM_IN[0][PROBABILITY]" id="ITEM_IN[0][PROBABILITY]"size="5" maxlength="3"value="" /></td>[/HTML]
Jun 28 '07 #2

acoder
Expert Mod 15k+
P: 16,027
You're using the same name for the function and the name/id of the text element. Choose a different name for one of the two.
Jun 28 '07 #3

acoder
Expert Mod 15k+
P: 16,027
I've merged the two threads.

You can use isNaN to check if a value is a number.
Jun 28 '07 #4

Post your reply

Sign in to post your reply or Sign up for a free account.