Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jquery, post multiple variables

Tags:

jquery

I am brand new to jquery and trying to modify a basic script from php academy.

the jquery script is:

<script type="text/javascript">
function get() {
    $.post('getpeopleinjobs.php', {
        postvarfname: form.firstname.value,
        postvarlname: form.d = surname.value
    }, function(output) {
        $('#age').html(output).show();
    });
}
</script>

and my form code is:

    <form name="form">
    <input type="text" id="firstname">
    <input type="text" id="surname">
    <input type="button" value="get" onclick="get();">
    </form>

This worked perfectly when I was passing just one variable and my code snippet was:

$.post('getpeopleinjobs.php', {
    postvarfname: form.firstname.value
}

I then tried to add a second variable with

$.post('getpeopleinjobs.php', {
    postvarfname: form.firstname.value,
    postvarlname: form.d = surname.value
}

It does not work now in Internet Explorer but interestingly enough it does work in Chrome?

Any advice for the beginner?=

like image 895
Smudger Avatar asked Dec 01 '22 22:12

Smudger


1 Answers

You have the concept down correctly but there appears to be a minor mistake

//Posted Code
$.post ('getpeopleinjobs.php',{postvarfname: form.firstname.value,postvarlname: form.d=surname.value}
// Fixed Code
$.post ('getpeopleinjobs.php',{postvarfname: form.firstname.value, postvarlname: form.surname.value}
like image 135
Josh Mein Avatar answered Dec 27 '22 17:12

Josh Mein