PDA

View Full Version : Onclick event for a link...



jnscollier
03-24-2007, 07:50 PM
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)

thetestingsite
03-24-2007, 07:55 PM
Place this part between the head tags:



<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:




<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.

jnscollier
03-24-2007, 08:14 PM
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!!!!

thetestingsite
03-24-2007, 08:17 PM
Sorry, made a typo in the code. Try copying the part that goes in the head again.

jnscollier
03-24-2007, 08:20 PM
Excellent!!!!!! Thank You!

jnscollier
03-24-2007, 09:14 PM
How would you make the form disappear with a reset button, is that another onclick event??

jnscollier
03-24-2007, 09:18 PM
Nevermind!! I used an onclick for the button and just made another function called hideForm.