onchange event problem !!!

Discussion in 'Javascript' started by Brami Yair, Jul 7, 2004.

  1. Brami Yair

    Brami Yair Guest

    below is example HTML code:
    <input type=text onchange="javascript:alert('text change');">"

    When i type something into the box, the onChange event fires,
    but, when i change this box in code, the onChange event should fire but it doesn't.

    why, and what i can do ?
    Brami Yair, Jul 7, 2004
    #1
    1. Advertising

  2. Brami Yair

    Mick White Guest

    Brami Yair wrote:

    > below is example HTML code:
    > <input type=text onchange="javascript:alert('text change');">"


    <input type=text onchange="alert('text change');">

    Mick

    >
    > When i type something into the box, the onChange event fires,
    > but, when i change this box in code, the onChange event should fire but it doesn't.
    >
    > why, and what i can do ?
    Mick White, Jul 7, 2004
    #2
    1. Advertising

  3. Brami Yair

    Grant Wagner Guest

    Mick White wrote:

    > Brami Yair wrote:
    >
    > > below is example HTML code:
    > > <input type=text onchange="javascript:alert('text change');">"

    >
    > <input type=text onchange="alert('text change');">
    >
    > Mick
    >
    > > When i type something into the box, the onChange event fires,
    > > but, when i change this box in code, the onChange event should fire but it doesn't.
    > >
    > > why, and what i can do ?


    If you change the value programmatically, then you have to call the "onchange()" method
    of the element you are changing programmatically as well:

    <form name="myForm">
    <input type="text"
    name="myInput"
    value="old text"
    onchange="alert('text changed');">
    <input type="button"
    value="Change text"
    onclick="changeInput('new text', this.form.elements['myInput']);">
    </form>
    <script type="text/javascript">
    function changeInput(s, element) {
    element.value = s;
    // the next line fires the onchange event of the element
    element.onchange();
    }
    </script>

    --
    | Grant Wagner <>

    * Client-side Javascript and Netscape 4 DOM Reference available at:
    * http://devedge.netscape.com/library/manuals/2000/javascript/1.3/reference/frames.html
    * Internet Explorer DOM Reference available at:
    * http://msdn.microsoft.com/workshop/author/dhtml/reference/dhtml_reference_entry.asp
    * Netscape 6/7 DOM Reference available at:
    * http://www.mozilla.org/docs/dom/domref/
    * Tips for upgrading JavaScript for Netscape 7 / Mozilla
    * http://www.mozilla.org/docs/web-developer/upgrade_2.html
    Grant Wagner, Jul 7, 2004
    #3
  4. Brami Yair

    Brami Yair Guest

    Grant Wagner <> wrote in message news:<>...
    > Mick White wrote:
    >
    > > Brami Yair wrote:
    > >
    > > > below is example HTML code:
    > > > <input type=text onchange="javascript:alert('text change');">"

    > >
    > > <input type=text onchange="alert('text change');">
    > >
    > > Mick
    > >
    > > > When i type something into the box, the onChange event fires,
    > > > but, when i change this box in code, the onChange event should fire but it doesn't.
    > > >
    > > > why, and what i can do ?

    >
    > If you change the value programmatically, then you have to call the "onchange()" method
    > of the element you are changing programmatically as well:
    >
    > <form name="myForm">
    > <input type="text"
    > name="myInput"
    > value="old text"
    > onchange="alert('text changed');">
    > <input type="button"
    > value="Change text"
    > onclick="changeInput('new text', this.form.elements['myInput']);">
    > </form>
    > <script type="text/javascript">
    > function changeInput(s, element) {
    > element.value = s;
    > // the next line fires the onchange event of the element
    > element.onchange();
    > }
    > </script>
    >
    > --
    > | Grant Wagner <>
    >
    > * Client-side Javascript and Netscape 4 DOM Reference available at:
    > * http://devedge.netscape.com/library/manuals/2000/javascript/1.3/reference/frames.html
    > * Internet Explorer DOM Reference available at:
    > * http://msdn.microsoft.com/workshop/author/dhtml/reference/dhtml_reference_entry.asp
    > * Netscape 6/7 DOM Reference available at:
    > * http://www.mozilla.org/docs/dom/domref/
    > * Tips for upgrading JavaScript for Netscape 7 / Mozilla
    > * http://www.mozilla.org/docs/web-developer/upgrade_2.html


    thanks :)
    Brami Yair, Jul 8, 2004
    #4
    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,105
    pelegk1
    Jul 15, 2007
  2. archana
    Replies:
    1
    Views:
    2,866
    Gregory A. Beamer
    Aug 14, 2009
  3. Covad
    Replies:
    1
    Views:
    189
    Richard Cornford
    Nov 3, 2003
  4. Lee Mundie

    OnChange Event Problem - Please Help

    Lee Mundie, Nov 19, 2003, in forum: Javascript
    Replies:
    3
    Views:
    96
    Richard Cornford
    Nov 19, 2003
  5. Senthil

    Problem with OnChange event of TextBox

    Senthil, Nov 18, 2004, in forum: Javascript
    Replies:
    0
    Views:
    154
    Senthil
    Nov 18, 2004
Loading...

Share This Page