Results 1 to 7 of 7

Thread: Onclick event for a link...

  1. #1
    Join Date
    Jan 2007
    Posts
    94
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Cool Onclick event for a link...

    Quick question, and I think you need javascript for this... i'm not too sure...

    I'd like to have a link where if it's clicked it a little form displays (basically just 2 textboxes and a submit button). How can I go about doing this?

    (I don't know if you would need to know this, but i'm using php)

  2. #2
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    Place this part between the head tags:

    Code:
    <script type="text/javascript">
     
    function showForm(eid) {
    
       if (document.getElementById(eid).style.display == "none") {
         document.getElementById(eid).style.display = "block";
      }
    
      else {
         document.getelementById(eid).style.display = "none";
      }
    
    }
    
    </script>
    and this in the body somewhere:

    Code:
    <a href="#" onclick="showForm('theForm'); return false;">Show the form</a>
    
    <div id="theForm" style="display: none;">
    
     <form action="test.php" method="POST">
       Text 1: <input type="text" name="text1"> <br>
       Text 2: <input type="text" name="text2"> <br>
       <input type="submit" value="Submit">
     </form>
    
    </div>
    Not tested, but should work. Hope this helps.
    Last edited by thetestingsite; 03-24-2007 at 08:16 PM.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  3. #3
    Join Date
    Jan 2007
    Posts
    94
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default

    well, it looks like what i need, but it shows that there are javascript errors I think, so it doesn't work when I click the link.

    Any help would be appreciated... THANK YOU!!!!

  4. #4
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    Sorry, made a typo in the code. Try copying the part that goes in the head again.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  5. #5
    Join Date
    Jan 2007
    Posts
    94
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default

    Excellent!!!!!! Thank You!

  6. #6
    Join Date
    Jan 2007
    Posts
    94
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default

    How would you make the form disappear with a reset button, is that another onclick event??

  7. #7
    Join Date
    Jan 2007
    Posts
    94
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default

    Nevermind!! I used an onclick for the button and just made another function called hideForm.

Bookmarks

Posting Permissions

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