Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Javascript to submit forms

EDIT: For some reason if I change the input into an , the submit code works fine. Ok, this works, I'll just style the a tag to look like an input tag in css.

I am using a jQuery function to submit a form when a certain button is pressed, however this seems to have no effect on the form.

My code is as follows: HTML:

<form id="loginForm" action="" method="POST">
    <input class="loginInput" type="hidden" name="action" value="login">
    <input id="step1a" class="loginInput" type="text" name="username">
    <input id="step2a" class="loginInput" type="password" name="password"  style="display:none;">
    <input id="step1b" class="loginSubmit" onclick="loginProceed();" type="button" name="submit" value="Proceed" title="Proceed" />
    <input id="step2b" class="loginSubmit" onclick="submitlogin();" type="button" value="Validate" title="Validate"  style="display:none;" />
</form>

Javascript:

function submitlogin()
{
    $("#loginForm").submit();
}

function loginProceed()
{
    $("#step1a").fadeOut("slow",function(){
        $("#step2a").fadeIn("slow", function(){
            $("#step2a").focus();
        });
    });
    $("#step1b").fadeOut("slow",function(){
        $("#step2b").fadeIn("slow");
    });
    $("#step1c").fadeOut("slow",function(){
        $("#step2c").fadeIn("slow");
    });

}

However, when I press the button, absolutely nothing occurs.

PS. This function may seem meaningless since I can just use a input type="submit" but I originally intended this to have some more functionality, I stripped the function to its bare bones for testing purposes.

like image 655
Razor Storm Avatar asked Dec 22 '22 02:12

Razor Storm


2 Answers

Try to use another name for input with name="submit". Without this it works fine for me.

like image 57
vtambourine Avatar answered Jan 09 '23 09:01

vtambourine


You need to specify one form.

$("#loginForm").submit();
like image 41
Pekka Avatar answered Jan 09 '23 10:01

Pekka