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 3 of 3
  1. #1
    Regular Coder
    Join Date
    Jun 2002
    Location
    Provo, UT
    Posts
    142
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Changing the onClick function call dynamically

    okokokokok,

    here is the deal. I have a common button right.

    <input type="button" id="myButton" onClick="changeStuff();" value="Change Stuff">

    And what the changeStuff function wants to do is change the value and change which function the onClick calls. This is how I think the function would go.

    Code:
    function changeStuff(){
      document.getElementById('myButton').value = "Change Back";
      document.getElementById('myButton').onClick = changeBack;
    }
    
    // and the the changeback function would be like ...
    
    function changeBack(){
      document.getElementById('myButton').value = "Change";
      document.getElementById('myButton').onClick = changeStuff;
    }
    So I have tried this and it doesn't work so my question is how do you change the function the button calls onClick dynamically. Can it be done.

    Thanks for the responses.
    I try to convince 'em that I am computer geek, but I just can't do it. Why? Oh why?

  • #2
    Regular Coder
    Join Date
    Jun 2002
    Location
    Provo, UT
    Posts
    142
    Thanks
    0
    Thanked 0 Times in 0 Posts
    OOOOOOOH CRAP.

    Sorry guys.

    i got it

    it jsut needs to be

    [code]document.getElementById('myButton').onclick = changeBack;[\code]

    BLAH

    Sorry.

    Feel free to erase this pfine piece of embarassment from the archives of my history.

    Thanks.
    I try to convince 'em that I am computer geek, but I just can't do it. Why? Oh why?

  • #3
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    U may use this as well:

    object.onclick=function(){
    ..statements, methods, functions, etc...
    }
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*


  •  

    Posting Permissions

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