-2

sorry for my English, it's not my national lang.

My question is next:

I wanna post values of all inputs of the form to php file and get the answer and write it in div.

For example:

I have a form with blank div before it:

<div id="msg" name="msg"></div>

<form method="???" action="???">
<input type="text" name="login" id="login" value="" />
<input type="password" name="passwd" id="passwd" value="" />
<input type="submit" value="send" />
</form>

And when I click "send" it should send all values of inputs to, for example, register.php, WITHOUT page refresh, and div with id "msg" should get, what php answers. For example, it answers "Account registered successfully", and it appears in this div. How can I do this? (desirable to use jQuery).

Vasily
  • 27
  • 2

3 Answers3

1

Add name attribute to the form, on your submit button call an ajax function to submit the data dynamically to register.php and on success replace the message in the innerHtml of the div.

for help refer these links:

https://stackoverflow.com/a/8820803/1687983

Ajax Form Submit with submit button

Community
  • 1
  • 1
Coder anonymous
  • 917
  • 1
  • 8
  • 25
0

Use should use jQuery ajax functionality http://api.jquery.com/jQuery.post/ http://api.jquery.com/jQuery.ajax/

see this question: Submit a form using jQuery

and this question: Submit form using AJAX and jQuery

There is more then enough documentation available already. Have you even searched for a solution?

Community
  • 1
  • 1
Yoeri
  • 2,249
  • 18
  • 33
0

You should use the jQuery event : submit, to interpret a submission, like so:

$('form#regForm').submit( function() {
   $.post( 'register.php', $('form#regForm').serialize(), function(data) {
       //Use the data to understand how the registration went.
       $("#msg").html("Good/Bad");
   }
   return false;
);
});

the HTML:

<div id="msg" name="msg"></div>
<form id="regForm" method="post" action="register.php">
    <input type="text" name="login" id="login" value="" />
    <input type="password" name="passwd" id="passwd" value="" />
    <input type="submit" value="send" />
</form>
nadavge
  • 590
  • 1
  • 3
  • 14