0

Right now I am updating user_list List using jquery and submitting the form data using Ajax

now I want to submit that form like normal form submit

Here is the problem I am unable to pass the JQuery updated user_list along form ?

Is There any way to do this ?

What I have tried

<script>

var user_names=[];

function check_selected(id){

    user_names.push(id);

        $("#username").val(user_name);

}
</script>

Where username is a form field like

<input type ="hidden" val = "" id="username" name ="username">
1
  • You need to add more detail, at the moment, your question is difficult to understand, perhaps provide more details of what you would like to happen. Commented Sep 15, 2012 at 9:12

3 Answers 3

1

val is not a valid attribute for the <input /> element. Change it to value

<input type="hidden" value="" id="username" name="username" />
Sign up to request clarification or add additional context in comments.

1 Comment

oh i am sorry i forget to do that
0

I am not sure if this will help or not, but you have used a variable that may have not been initialized

$("#username").val(user_name);

should be

$("#username").val(user_names);    //missing s

besides, if you are after sending an array to the server, and the server is php, I would suggest adding [] square brackets at the end of the field name, this is a clean way of sending the list and the server can build the array and you would be able to access it as a list

 $_POST['list_name'][index]

Comments

0

Try this

<script>

var user_names=[];

function check_selected(id){

    user_names.push(id);

        $("#username").val(user_names.join(","));

}
</script>

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.