SitePoint Sponsor

User Tag List

Results 1 to 7 of 7

Thread: Event Handling

  1. #1
    SitePoint Member
    Join Date
    Dec 2004
    Location
    Cumbria, UK
    Posts
    18
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Event Handling

    I understand that with a HTML text field onchange fires when the field loses focus and it's value has changed, but this does not work if the value is changed by Javascript i.e. by assigning a new value to document.form.myField.value property.

    I was wondering if there is any way to call an event handling function upon any change to the value of a text field as onchange is designed to detect changes to the value made by the user.

    My reason for not simply calling my event handler from the script that changes the value is that I am using a library script to draw a calendar and I dont want to change this library code.

    Any help or views would be appreciated, thanks

    Paul

  2. #2
    SitePoint Wizard Pepejeria's Avatar
    Join Date
    Jan 2005
    Location
    Too far up north
    Posts
    1,566
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Whatever function you call with the onchange event, can also be called after you change the input value with javascript. Just add the function call after that line.

  3. #3
    SitePoint Member
    Join Date
    Dec 2004
    Location
    Cumbria, UK
    Posts
    18
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks,

    I would ideally prefer not to change the code that writes the new value to the field but I may have to do it this way!

    I know there is no other event handling attributes to listen for changes to a text field but I was hoping for an alternative to changing the library code.

    Cheers
    Paul

  4. #4
    SitePoint Wizard Pepejeria's Avatar
    Join Date
    Jan 2005
    Location
    Too far up north
    Posts
    1,566
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That would be the fastest simplest solution. IE has onpropertychange, but that is not supported by other browsers.

  5. #5
    SitePoint Member
    Join Date
    Dec 2004
    Location
    Cumbria, UK
    Posts
    18
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I have used onpropertychange as a solution as my application will only be viewed using IE.

    This event is fired when any property is changed, such as color, disabled etc. Therefore I check the value of window.event.propertyName and only act if it is 'value'.

    I realise this solution is not portable but that shouldnt worry me at the present time. Thanks for your help!

  6. #6
    SitePoint Evangelist SpaceFrog's Avatar
    Join Date
    Jan 2005
    Location
    Outerspace
    Posts
    511
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    onkeyup ?

  7. #7
    SitePoint Member
    Join Date
    Dec 2004
    Location
    Cumbria, UK
    Posts
    18
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    My original problem was that I needed to respond to changes to the value property other than the user typing. I was using onkeyup and onkeypress along with onchange in certain fields until this became the case, and then javascript was used to change the value dynamically and this is where onpropertychange comes in - a way to detect any changes to the field not just user typing.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •