Question

I have a multipe select as part of my imput form and I would like to submit it's selected values via jQuery AJAX.

I've tried to use the following syntax.

$('#multipleselect').val().join('|');

That works, bu the problem I am having is that the user is not required to select anything from the multiple select. If they don't I get an error because you cannot join a null object.

Any Suggestions?

Also keep in mind that there are other values being submitted. For example:

data: "name=" + $("#name").val() + "&multipleselect=" + $("#multipleselect").val().join('|');
Was it helpful?

Solution

You can use serialize method:

Encode a set of form elements as a string for submission.

var data = $('form').serialize()
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top