Programmatically call onChange handler

ajax , javascript Derby, United Kingdom
  • 13 years ago

    I am using a popup calendar to populate an input field. When the contents of this field change I need the onChange event to fire so that I can perform further updates. The onChange event "onChange=myFunction()" will fire if I manually type the date into the field but not if I populate the field using javascript!

    How can I programatically invoke the onchange event?

  • 13 years ago

    Hi,

    I have just overcome a similar problem in which I had an input box which accepted the staff id of an employee, upon entering a valid staff id in this box, the onchange handler would fire and select the corresponding department that the employee works in from a dropdown list.  This worked fine but, as with your problem, when I added the ability for the user to select an employee from a drop down list in a pop-up window, I could not get the onchange event of the input box to fire. 

    I got around it by firing the formHandler function on the main page just before closing the calling page.  Here is my formHandler function which just reloads the page and uses the querystring to pass the contents of my text box:

    function formHandler(theForm){
    //on the main page
     if (login.Text1.value.length==6){
      var URL = "default.asp?fired=yes&id="+document.forms(0).elements('Text1').value+"&date="+document.forms(0).elements('Text2').value;
      window.location.href = URL;
     }

    And just before I close the pop-up window I invoke my function with:

    'In the popup window
    response.write"<script language='javascript'>window.opener.document.login.Text1.value=""" & strSelection & """</script>"
      response.write"<script language='javascript'>window.opener.formHandler(window.opener.document.forms[0]);</script>"
      response.write "<script language='javascript'>window.close();</script>"

















  • 13 years ago

    Thanks for prompt and comprehensive response Rob. However, I don't believe your solution will work in my case because, as I neglected to mention, I am using AJAX and therefore do not close /reload my page. Any ideas?

     

Post a reply

Enter your message below

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“In theory, theory and practice are the same. In practice, they're not.”