tapaljor
tapaljor

Reputation: 257

How to pass value of multiple input form in jQuery ajax?

I have multiple input form. Once I put value and I should able to pass it through jQuery Ajax. It's working on simple html form. But in terms of multi-dimension form I fail.

Please help me get value in jQuery.

I have html form

<form action="index.php" method="POST">
<?php
     for($a=0; $a<5; $a++) {
         echo "<input type='text' name='IdentityID[]' placeholder='GB' onchange=\"getdetail(IdentityID[id]); return false;\"/>";
     }
?>
</form>

JQuery ajax

function getdetail(IdentityID) {

     alert(IdentityID); //I wan the value to appear here

     $.ajax ({
             type: "POST",
             url: "getdetail.php",
             data: { IdentityID: IdentityID},
             success: function(data) {
                     $("#detail").html(data);
             }
     });
     return false;
}

ReferenceError: IdentityID is not defined

Upvotes: 1

Views: 1286

Answers (3)

tapaljor
tapaljor

Reputation: 257

<input type="text" onchange="getdetail(this.value)"/>

That is the answer. Thanks to @guest271314

Upvotes: 0

guest271314
guest271314

Reputation: 1

Substitute this.value for IdentityID[id] at onchange=\"getdetail(IdentityID[id])

Upvotes: 1

Saadi
Saadi

Reputation: 1294

Serialise whole of the form using;

var dataVal = $('form').serializeArray();

and then you ajax request becomes:

$.ajax ({
             type: "POST",
             url: "getdetail.php",
             data: dataVal,
             success: function(data) {
                     $("#detail").html(data);
             }
     });

Upvotes: 0

Related Questions