OnChange Event

Discussion in 'Javascript' started by crjunk, Aug 23, 2005.

  1. crjunk

    crjunk Guest

    I have a javascript that will output a message telling the user that
    changes were made. It halfway works. If the user enters in a number,
    the TextChanged function executes and displays the "Changes Made"
    message, but if the user deletes a number by using the BACKSPACE key or
    the DELETE key on the keyboard, the function does not run. Am I using
    the wrong event handler?


    function TextChanged(){
    document.ScheduleForm.txtRecordStatus.value = "Changes Made; Record Not
    Saved.";
    document.ScheduleForm.txtRecordStatus.style.color = "#FF0000";
    }


    <input type='text' name='txtGrossPayroll1' value='1' width='10'
    onBlur='TotalPremium(7)' onkeyup='ComputePremium(1)'
    onchange='TextChanged()' onkeypress='return blockNumbers(event)'/>

    Thanks,
    CR Junk
     
    crjunk, Aug 23, 2005
    #1
    1. Advertising

  2. crjunk

    ASM Guest

    crjunk wrote:
    > I have a javascript that will output a message telling the user that
    > changes were made. It halfway works. If the user enters in a number,
    > the TextChanged function executes and displays the "Changes Made"
    > message, but if the user deletes a number by using the BACKSPACE key or
    > the DELETE key on the keyboard, the function does not run. Am I using
    > the wrong event handler?
    >
    >
    > function TextChanged(){
    > document.ScheduleForm.txtRecordStatus.value = "Changes Made; Record Not
    > Saved.";
    > document.ScheduleForm.txtRecordStatus.style.color = "#FF0000";
    > }
    >
    >
    > <input type='text' name='txtGrossPayroll1' value='1' width='10'
    > onBlur='TotalPremium(7)' onkeyup='ComputePremium(1)'
    > onchange='TextChanged()' onkeypress='return blockNumbers(event)'/>


    I think you'll have to choice between onblur and onchange
    because their jobs (of event) are very close
    Wich one will fire first ?

    try something like that :

    onfocus="truc=this.value;"
    onkeypress="return blockNumbers(event);"
    onkeyup='ComputePremium(1)'
    onblur="TotalPremium(7);if(this.value!=truc)TextChange();"

    --
    Stephane Moriaux et son [moins] vieux Mac
     
    ASM, Aug 23, 2005
    #2
    1. Advertising

  3. crjunk

    RobG Guest

    crjunk wrote:
    > I have a javascript that will output a message telling the user that
    > changes were made. It halfway works. If the user enters in a number,
    > the TextChanged function executes and displays the "Changes Made"
    > message, but if the user deletes a number by using the BACKSPACE key or
    > the DELETE key on the keyboard, the function does not run. Am I using
    > the wrong event handler?


    onchange should fire when the element loses focus if its value has
    changed. In some circumstance it fires earlier - different
    circumstances in different browsers on different elements - but its
    behaviour for input elements is pretty standard.

    The only key press that should cause an onchange on a text input to fire
    is one that moves focus off the element.

    Having both onblur and onchange on the same control may create issues,
    you will need to test thoroughly to ensure consistent behaviour.

    > function TextChanged(){
    > document.ScheduleForm.txtRecordStatus.value = "Changes Made; Record Not
    > Saved.";
    > document.ScheduleForm.txtRecordStatus.style.color = "#FF0000";
    > }
    >
    >
    > <input type='text' name='txtGrossPayroll1' value='1' width='10'
    > onBlur='TotalPremium(7)' onkeyup='ComputePremium(1)'
    > onchange='TextChanged()' onkeypress='return blockNumbers(event)'/>
    >
    > Thanks,
    > CR Junk
    >



    --
    Rob
     
    RobG, Aug 24, 2005
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Zeebra3
    Replies:
    5
    Views:
    5,121
    pelegk1
    Jul 15, 2007
  2. MDBloemker
    Replies:
    2
    Views:
    2,856
  3. Norm via DotNetMonster.com

    using the client side "onchange" event function

    Norm via DotNetMonster.com, Jun 15, 2005, in forum: ASP .Net
    Replies:
    3
    Views:
    4,858
    Norm via DotNetMonster.com
    Jun 15, 2005
  4. Chris  Ashley

    Onchange event - need to click out?

    Chris Ashley, Dec 6, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    707
    Karl Seguin
    Dec 6, 2005
  5. Vitthal Bhat

    OnChange() Event in Struts

    Vitthal Bhat, Feb 17, 2005, in forum: Java
    Replies:
    6
    Views:
    9,925
    augur
    Feb 19, 2005
Loading...

Share This Page