I’ve got this really frustrating problem. I want to submit a form with Javascript and no matter what I try I always end up getting Uncaught exception: TypeError: Cannot convert 'document.getElementById('loginForm')' to object.
I’ve been staring at this code for some time now and I really can’t figure it out. I’m sure it’s really simple, but I just can’t see the solution.
Here is my code:
<form method="post" action="do.php?a=signin" id="loginForm">
<input name="usr" class="test" placeholder="Användarnamn" type="text" />
<input name="pwd" class="test" placeholder="Lösenord" type="password" />
</form>
<span class="test"><a href="fblogin.php"><img src="gfx/ico/fb.jpg" alt="" /> Logga in via Facebook</a></span>
<span class="test"><a href="javascript: doLogin();"><img src="gfx/ico/Unlock.gif" alt="" /> Logga in »</a></span>
<script type="text/javascript">
function doLogin() {
document.getElementById('loginForm').submit();
}
</script>
What am I missing!?
The solution was that I accidentally had entered another
<form>earlier in my code. I removed it and now it works like a charm!