2

I am using a short script to post from data to a PHP processing page.

function get(){
    $.post('data.php',{name: form.name.value},
        function(output) {
        $('#age').hide().html(output).fadeIn(1000);
        }
    );
}

This will only send one from input:

$.post('data.php',{name: form.name.value},

I am wondering how do I alter the script to send more then one ?

2 Answers 2

8
function get() {
   $.post('data.php', $('form').serialize(),
     function(output){
      $('#age').hide().html(output).fadeIn(1000);
   });
}

This assumes you want to send all form inputs. Alternatively, you could replace that with an object literal such as...

{
    name: $('input[name="name"]').val(),
    age: $('#age').val()
}
Sign up to request clarification or add additional context in comments.

1 Comment

Cheers mate. Very helpful and thanks for fixing up the code. I'm still getting my head around how it all works here.
1

use id on your form fields ex: <input type="text" id="firstname"> <input type="text" id="lastname">

$.post('data.php',{"name":$('#firstname').val(),"lastname":$('#lastname').val()},function(data){
   do stuff like update the table or something..
});

1 Comment

@ ricky Thanks a lot mate. That helped me even more with getting this script working.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.