0

i have a form with 2 fields which is having jquery token based input, they can have single or multiple value, what is the way to capture the data from both input fields(which contains multiple values), which i should be able to distinguish based on the input field id. i intend to process this data in php script, so is it possible to get the input directly in ($_POST)

<div>
<h2>Include</h2>
    <input type="text" id="include" name="include" />


<h2>Must Have</h2>

    <input type="text" id="must_have" name="must_have" />

    <input type="button" value="Submit" />
</div>

jquery script to view the data when u hit the submit button. (it is currently showing me the data of include field only (example:- k1,k2,k3)) but it is not showing me for must_have field.

$(document).ready(function() {
    $("input[type=button]").click(function () {
        alert("Would submit: " + $(this).siblings("input[type=text]").val());
    });
});

i am new to jquery, so i dont know exaclty how to process this. please help.

7
  • "so is it possible to get the input directly in ($_POST)" Where else do you think it's going? Commented Feb 7, 2013 at 10:58
  • i am using jquery autosuggest multiple token input mechanism in this input field, so it is possible to get the data directly in $_POST or i need to do something else,(to get the data in JS , then pass it to php via JSON) Commented Feb 7, 2013 at 11:03
  • all fields within the form, except unchecked checkboxes, get posted Commented Feb 7, 2013 at 11:04
  • so if my include field contains (k1,k2,k3), then i am able to get it via $_POST['include']; ? Commented Feb 7, 2013 at 11:07
  • just use the <?php var_export($_POST); ?> in your php script and you will see all data posted :) Commented Feb 7, 2013 at 11:15

2 Answers 2

1

Try to use each to iterate on input text elements.

$(document).ready(function() {
    $("input[type=button]").click(function () {
        $(this).siblings("input[type=text]").each(function(i,elt){alert("Would submit: " + elt.val());});
    });
});
Sign up to request clarification or add additional context in comments.

1 Comment

jsfiddle is a great tool, i forgot it :)
0

Try this:

$(document).ready(function() {
$("input[type=button]").click(function () {
var input1 = $("#include").val();
 var input2 = $("#must_have").val();
    alert("Would submit: " + input1 + "&" + input2);
});
});

2 Comments

this thing works. thank a lot, Now i am considering can i directly use this data in php, without touching Jquery ? or can i directly take the data input in PHP variable?
umm, What do you mean? Tell me, do you want to process two fields value on the same page with only using PHP or JQuery?

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.