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

Thread: buttan onClick

  1. #1
    New to the CF scene
    Join Date
    Jan 2013
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    buttan onClick

    Hey there!

    I've just started with all this website building stuff and now I'm stuck.

    I'm struggling with a function that I cannot get to work. The thing is actually pretty simple, but I am out of ideas and so is Google.

    What I want to do is: when the 'Login' button is clicked, there should appear an extension under the button, where users can fill in their log-in information.

    Since I am a total beginner, I tried to work it out from a bit of code from W3Schools' website. Unfortunately, it didn't work, but anyway: here is what I have got at the moment.

    Code:
    <script type="text/javascript"> 
    	function menu-dropdown() {
    		document.getElementById("ddlogin").innerHTML="login";
    	}
    </script>
    The code above was just a check, if it outputs anything, but nothing was shown.

    I also tried to insert <form> right into "innerHTML="here";".

    I'm sorry for being a total newbie, but I feel like I can't continue if this thing remains a mistery for me. So, please don't judge me too hard.

    I will provide some pictures:



  • #2
    Senior Coder xelawho's Avatar
    Join Date
    Nov 2010
    Posts
    2,969
    Thanks
    56
    Thanked 557 Times in 554 Posts
    if it's an entire form you are better off hiding it on page load and showing it when the button is pressed:

    Code:
    <!doctype html>
    <html>
    <head>
    <style>
    #myform{
    display:none;
    }
    </style>
    </head>
    <body>
    <input type="button" value="show form" onclick="showIt()"/>
    <form id="myform">
    <input/><br>
    <input/>
    </form>
    <script>
    function showIt(){
    document.getElementById("myform").style.display="block";
    }
    </script>
    </body>
    </html>

  • #3
    Senior Coder Dormilich's Avatar
    Join Date
    Jan 2010
    Location
    Behind the Wall
    Posts
    3,286
    Thanks
    12
    Thanked 344 Times in 340 Posts
    Quote Originally Posted by swenn View Post
    Code:
    function menu-dropdown() {
    "SyntaxError: missing ( before formal parameters"

    in other words, - is not a valid character for a variable/function name.
    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
    •