Hello,
I'm new to javascript and can't figure out how to do this. What I want is that there when you click on 'login', underneath it a form appears with 2 fields and a submit button.
Now, I can manage the form, but I don't know how to do the javascript part... Can someone get me started please?
I've searched through the w3schools examples but havn't found what I was looking for..
show form on onclick
Moderator: General Moderators
Re: show form on onclick
HTML:
JS to show the form:
To position form under the link use CSS
Code: Select all
<!-- Link -->
<a href="/login" onclick="return showLoginForm();">Login</a>
<!-- Hidden form (display: none in css) -->
<form id="loginForm">...</form>Code: Select all
function showLoginForm() {
//Show form
var form = document.getElementById('loginForm');
form.style.display = block;
//Prevent from actually going to /login page
return false;
}Re: show form on onclick
Thanks for your reply.
Does the javascript have to be in the <head> ?
Because I put it in the head part and the form just shows, without clicking on login..
Does the javascript have to be in the <head> ?
Because I put it in the head part and the form just shows, without clicking on login..
Re: show form on onclick
You should learn CSS, HTML and JS. Useful Resources post should be a good start.