This topic is locked

assigning a javascript to execute onchange

10/20/2007 12:14:43 AM
PHPRunner General questions
G
giles author

Hi,

Having trouble getting a javascript executed when an onchange event occurs at a text field on a page.
Here's the bit in the javascript where I'm trying to set this up...
// make the following fields update the prices on change...

alert(document.getElementById("value_somefield").onchange)

//document.getElementById("value_somefield").onchange='myscript("13")';

document.forms.editform.value_somefield.onchange = 'myscript("13")';

alert(document.getElementById("value_somefield").onchange)

The alerts are in there just to show what's happening...
On the first alert I get "undefined" - as expected since the onchange has not been set up.

On the second I get "myscript("13")" - which seems to indicate the event handler has been set.
But the event does not get triggered by a change in the value of "somefield".
I know the javascript function "myscript" is working as I can link it via Visual Editor to an onclick or onmouseover event on buttons on the same page. Works fine when activated that way.
Can anyone help with correct syntax? Or let me know if it is not possible to set the event handler in this way.
Thanx
Giles

G
giles author 10/20/2007

Hmm...seem to be mnaking a habit of this...found the answer to my own question minutes after posting...
Seems the correct syntax for setting the event is...
document.getElementById("value_somefield").onchange = function() {myscript("13");};