Onblur does not work

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • coolguyraj
    New Member
    • Jun 2007
    • 8

    Onblur does not work

    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(docume nt.getElementBy Id('percentageg o').value);
    var val2 = parseInt(docume nt.getElementBy Id('percentagew in').value);
    var ansd = document.getEle mentById('proba bility');
    ansd.value = Math.round((val 1 * val2)/100);
    }
    </script>

    <th class="bodyText " align="right">% Go:&nbsp;&nbsp; </th>
    <td class="bodyText " colspan="2"><in put type="text" id="percentageg o" name="percentag ego" value="<?php
    if (!empty($percen tagego)) {
    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"><in put type="text" id="percentagew in" name="percentag ewin" onBlur="probabi lity()" value="<?php
    if (!empty($percen tagewin)) {
    echo number_format($ percentagewin,0 );
    }?>" maxlength="20" size="17"></td>
    </tr>
    <tr>
    <th class="bodyText " align="right">P robability:&nbs p;&nbsp;</th>
    <td class="bodyText " colspan="2"><in put type="text" onBlur="probabi lity()" name="probabili ty" id="probability " value="" maxlength="3" size="5"></td>
    </tr>[/HTML]
    Last edited by acoder; Jun 28 '07, 11:12 AM. Reason: Code in tags
  • coolguyraj
    New Member
    • Jun 2007
    • 8

    #2
    Javascript function does not work in firefox

    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(docume nt.getElementBy Id("ITEM_IN[0][PERCENTAGE_GO]").value);
    var val2 = parseInt(docume nt.getElementBy Id("ITEM_IN[0][PERCENTAGE_WIN]").value);
    var ansd = document.getEle mentById("ITEM_ IN[0][PROBABILITY]");
    ansd.value = Math.round((val 1 * 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="probabi lity0()" 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="reado nly" onBlur="probabi lity0()" name="ITEM_IN[0][PROBABILITY]" id="ITEM_IN[0][PROBABILITY]"size="5" maxlength="3"va lue="" /></td>[/HTML]
    Last edited by acoder; Jun 28 '07, 11:21 AM. Reason: Code in tags

    Comment

    • acoder
      Recognized Expert MVP
      • Nov 2006
      • 16032

      #3
      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.

      Comment

      • acoder
        Recognized Expert MVP
        • Nov 2006
        • 16032

        #4
        I've merged the two threads.

        You can use isNaN to check if a value is a number.

        Comment

        Working...