1

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

4
  • Where is id at onchange=\"getdetail(IdentityID[id]) defined? Commented Sep 24, 2016 at 7:00
  • Even if I used getdetail(IdentityID[$a]) I get console ReferenceError: IdentityID is not defined Commented Sep 24, 2016 at 7:05
  • Try substituting this.value for IdentityID[id] Commented Sep 24, 2016 at 7:13
  • Perfect. Its working. Commented Sep 24, 2016 at 8:52

3 Answers 3

1

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

Sign up to request clarification or add additional context in comments.

Comments

0

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);
             }
     });

1 Comment

There must be straight way to do this. Passing IdentityID once I move cursor from input field.
0
<input type="text" onchange="getdetail(this.value)"/>

That is the answer. Thanks to @guest271314

Comments

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.