Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    May 2012
    Posts
    20
    Thanks
    8
    Thanked 0 Times in 0 Posts

    event triger when a html inputField has a value set through javascript

    Is there a way to have an event triger when a html inputField has a value set through javascript?

    So for example

    Code:
    <input class='inputField' size="20"  type='text' name='num1'  onchange="doIt3();" > </td>  <br>                  
    
      function doIt3() {
          alert("here") ;
      }    
      
      function doIt2() {
          var hn = document.getElementById("num1");
          hn.value = "aaaa";
      }
    doIt2 runs it changes the value of num1. However the onchange=doIt3() will not trigger until the user goes into the field, manually changes the value and then leaves the field.

    Is there an event I can trigger when the value automatically changes?

    thanks

  • #2
    Regular Coder
    Join Date
    Aug 2010
    Posts
    974
    Thanks
    19
    Thanked 212 Times in 210 Posts
    Code:
    function doIt2() {
          var hn = document.getElementById("num1");
          hn.value = "aaaa";
    	doIt3();
      }

  • #3
    New Coder
    Join Date
    May 2012
    Posts
    20
    Thanks
    8
    Thanked 0 Times in 0 Posts
    thank you.
    However this is just a simple example.
    In reality, I would like the inputField to pass itself into the function.
    Then I can generically act on any control on my page.
    any other ideas?

    thanks

  • #4
    Senior Coder Dormilich's Avatar
    Join Date
    Jan 2010
    Location
    Behind the Wall
    Posts
    3,473
    Thanks
    13
    Thanked 361 Times in 357 Posts
    event handlers assigned through JavaScript can refer to the element via the keyword this.
    The computer is always right. The computer is always right. The computer is always right. Take it from someone who has programmed for over ten years: not once has the computational mechanism of the machine malfunctioned.
    André Behrens, NY Times Software Developer


  •  

    Posting Permissions

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