treehouse : what would you like to learn today?
Web Design Web Development iOS Development

[Solved] javascript style.display

  • thought I'd give javascript a go and do some simple stuff like show a div when an element is clicked. It seems pretty simple but I dont know why I'm getting the error - missing ";" ???

    Here's the stripped down code

    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="utf-8">

    <script type="text/javascript">
    function showContactForm()
    {
    document.getElementById{"contactForm").style.display="block";
    }
    </script>

    <style>
    #contactForm {display:none;}
    </style>
    </head>

    <body>
    <p id="call"><a href="#" onClick="showContactForm()"> Email </a> for a brochure.</p>

    <div id="contactForm" name="contactForm">
    <h3>Contact Us</h3>
    <form id="contact" name="contact">
    <table cellspacing="2px" border="0">

    <tbody>
    <tr><td><input value="Full Name" name="fullName" type="text" id="fullName" class="disappear" size="40" maxlength="40" onfocus="value=''"/></td></tr>
    <tr><td><input value="email" name="email" type="text" id="email" class="disappear" size="40" maxlength="40" onfocus="value=''"/></td></tr>
    <tr><td><input value="phone number" name="phone" type="text" id="phone" class="disappear" size="40" maxlength="40" onfocus="value=''"/></td></tr>
    <tr><td><textarea value="Question or Comment" name="comment" class="disappear" cols="40" rows="5" onfocus="value=''"></textarea></td></tr>
    <td><input type="submit" value="Submit" class="formbutton"/></td></tr>
    </tbody>
    </table>
    </form>
    </div><!-- end contact form div -->

    </body>
    </html>
  • In your code you have a curly brace where a parentheses should be

    // Won't work
    document.getElementById{"contactForm")

    // Will work
    document.getElementById("contactForm")
  • I hate it when I miss something like that - thx!