Change Event Handler Programatically

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Alan Little

    Change Event Handler Programatically

    I want to change the event handler for a form field, using JS code. But
    there doesn't seem to be a way to reference it. MyForm.SomeFiel d.onChange
    is undefined. Anyone know if there's a way to do this?

    --
    Alan Little
    Phorm PHP Form Processor

  • Lasse Reichstein Nielsen

    #2
    Re: Change Event Handler Programatically

    Alan Little <alan@n-o-s-p-a-m-phorm.com> writes:
    [color=blue]
    > I want to change the event handler for a form field, using JS code. But
    > there doesn't seem to be a way to reference it. MyForm.SomeFiel d.onChange
    > is undefined. Anyone know if there's a way to do this?[/color]

    document.forms['MyForm'].elements['SomeField'].onchange = function () {...}

    The property is "onchange" in all lower case. Also, you have to assign
    a function to it, not a string as in HTML.

    I prefer using the forms and elements properties, but most browsers will
    work without them


    /L
    --
    Lasse Reichstein Nielsen - lrn@hotpop.com
    Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit. html>
    'Faith without judgement merely degrades the spirit divine.'

    Comment

    Working...