Alex
Alex

Reputation: 97

Submit automatically a form with Jquery onchange event

I try to submit my form automatically when I change an input field but nothing happens but I can just display a message using "alert(message)",can you help me please!!!

My code :

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

 <html xmlns="http://www.w3.org/1999/xhtml">
   <head>
       <script type="text/javascript" src="script/jquery-1.8.3.min.js"></script>
   </head>
  <body>
       <form method="POST" id="form" action="">
           <fieldset>
              Text 1 : <input id="text1" type="text" name="text1" value="" />
              <input id="submit" type="submit" name='submit' value="Send"/>
           </fieldset>
        </form>

        <script>

             $('#form input[name=text1]').change(function(){
             $('#form').click();
             //alert("Changed!");// This works
              });
       </script>

 </body>

 </html> 
 <?php
   if (isset($_POST['submit'])){
    echo $_POST['text1'];
   }
  ?>

Upvotes: 1

Views: 6690

Answers (2)

nathangiesbrecht
nathangiesbrecht

Reputation: 940

Try:

$('#form input[name=text1]').change(function(){
    $("#submit").click();
});

Upvotes: 0

Adil Shaikh
Adil Shaikh

Reputation: 44740

Try this -

$('#form input[name=text1]').change(function(){
    $('#form').submit();    
});

http://api.jquery.com/submit/

Upvotes: 1

Related Questions