#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2013
    Location
    The Netherlands
    Posts
    14
    Rep Power
    0

    Onclick change function?


    Hey,

    I'm trying to change the buttons' function after i clicked it, but it won't work..

    my javascript is:
    Code:
    function showMenu() {
    document.getElementById('coolmenu').style.display = "block";
    document.getElementById('tabledescription').style.display = "block";
    document.getElementById('test').value = "Click here to hide menu";
    document.getElementById('test').onclick = "hideMenu()";
    }
    function hideMenu() {
    document.getElementById('coolmenu').style.display = "none";
    document.getElementById('tabledescription').style.display = "none";
    document.getElementById('test').value = "Click here to show menu";
    document.getElementById('test').onclick = "showMenu()";
    }
    And my HTML (the button) is:
    Code:
    <input type="button" id="test" value="Click here to show menu" onclick="showMenu()">
    So when i click the button, the menu shows up, and the value changes. But the onclick function doesnt change What should i do to fix it..

    Thanks
  2. #2
  3. No Profile Picture
    Super Moderator
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jul 2003
    Posts
    4,008
    Rep Power
    2791
    Why? It would be preferable to use a toggle inside of a function. Post all of your code, or use the following.
    Javascript Code:
    document.getElementById('test').onclick = hideMenu;
    [PHP] | [Perl] | [Python] | [Java] != [JavaScript] | [XML] | [ANSI C] | [C++] | [LUA] | [MySQL] | [FirebirdSQL] | [PostgreSQL] | [HTML] | [XHTML] | [CSS]

    W3Fools - A W3Schools Intervention.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2013
    Location
    The Netherlands
    Posts
    14
    Rep Power
    0
    Originally Posted by Winters
    Why? It would be preferable to use a toggle inside of a function. Post all of your code, or use the following.
    Javascript Code:
    document.getElementById('test').onclick = hideMenu;
    Thanks, ill test that first, if it doesnt work i can post full code here

    Edit: Thanks a lot Worked fine <3

IMN logo majestic logo threadwatch logo seochat tools logo