Lukáš Ježek
Lukáš Ježek

Reputation: 75

Form submitted via jquery Mozilla

I have the following simple form where instead of a submit type I use a href link. It works fine everywhere except for Firefox. If I click the LOGIN link nothing happens in Firefox. Any ideas please? I tried to replace a href=# with javascript:void but it did not help.

<script>
$(document).ready(function() {
   $("#login_submit").click(function() {
    event.preventDefault();
    $("#login_form").submit();
    return false;
  });
});
</script>

<?
if(isset($_POST['login']))
{
 echo "THE FORM WAS SENT";     
}
?>


<form id="login_form" action="<? echo $_SERVER['PHP_SELF']; ?>" method="POST">
    <input type="text" name="jmeno" />
    <input type="hidden" name="login" value=true />
    <a href="#" id="login_submit">LOGIN</a>

</form>

Upvotes: 0

Views: 60

Answers (2)

Apul Gupta
Apul Gupta

Reputation: 3034

Try this:

<script type="text/javascript">
$(document).ready(function() {
   $("#login_submit").click(function(event) {
    event.preventDefault();
    $("#login_form").submit();
    return false;
  });
});
</script>

And change the anchor tag to:

<a href="javascript:void(null);" id="login_submit">LOGIN</a>

Upvotes: 0

adeneo
adeneo

Reputation: 318222

You're missing the event argument, in Chrome and IE it's global, in Firefox it's not, so event.preventDefault() is probably an error.

$(document).ready(function() {
   $("#login_submit").click(function(event) {
    event.preventDefault();
    $("#login_form").submit();
    return false;
  });
});

Upvotes: 1

Related Questions