Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > onchange event problem !!!

Reply
Thread Tools

onchange event problem !!!

 
 
Brami Yair
Guest
Posts: n/a
 
      07-07-2004
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 ?
 
Reply With Quote
 
 
 
 
Mick White
Guest
Posts: n/a
 
      07-07-2004
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 ?

 
Reply With Quote
 
 
 
 
Grant Wagner
Guest
Posts: n/a
 
      07-07-2004
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 <(E-Mail Removed)>

* Client-side Javascript and Netscape 4 DOM Reference available at:
* http://devedge.netscape.com/library/...ce/frames.html
* Internet Explorer DOM Reference available at:
* http://msdn.microsoft.com/workshop/a...ence_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-deve...upgrade_2.html


 
Reply With Quote
 
Brami Yair
Guest
Posts: n/a
 
      07-08-2004
Grant Wagner <(E-Mail Removed)> wrote in message news:<(E-Mail Removed)>...
> 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 <(E-Mail Removed)>
>
> * Client-side Javascript and Netscape 4 DOM Reference available at:
> * http://devedge.netscape.com/library/...ce/frames.html
> * Internet Explorer DOM Reference available at:
> * http://msdn.microsoft.com/workshop/a...ence_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-deve...upgrade_2.html


thanks
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
javascript problem,onchange event not working archana ASP .Net 1 08-14-2009 03:07 PM
calling clientside js with onchange event Zeebra3 ASP .Net 5 07-14-2007 11:12 PM
Problem with OnChange event of TextBox Senthil Javascript 0 11-18-2004 03:58 PM
OnChange Event Problem - Please Help Lee Mundie Javascript 3 11-19-2003 12:30 PM
dynamic select element: problem with onchange event Covad Javascript 1 11-03-2003 02:02 AM



Advertisments