0

I'm able to successfully get all the values from a multi-select form into one nice delimited variable, but I can't figure out how to get the value to my PHP script? How do I get the 'output' value read by PHP's $_POST array? Any help would. Be. Awesome. :D

<script type="text/javascript">
function ValidatePageForm() {
    var result = new Array();

    $("#select-to option").each(function() {
        result.push($(this).val());
    });

    var output = result.join("-");  
    alert(output);


}
</script>
2
  • do you understand client-side vs server-side ? Commented Apr 24, 2013 at 4:34
  • Which value do you want go get where? I'm confused. Do you want get the value of $_POST "inserted" into jQuery or do you want to get the values from jQuery-function "inserted" into PHP? Commented Apr 24, 2013 at 5:15

3 Answers 3

1

suppose you have a form

<form>
<input type="hidden" name="output" id="output">
....
</form>

send javascript variable to HTML

var output = result.join("-");  
$('#output').val(output);

and when you submit the form you wil get data in $_POST['output']

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

1 Comment

You're amazing. So simple. It works :). You saved me. Seriously this front-end stuff throws me for a loop. BUT give me crazy back-end work and I'll knock your socks off!
0

I believe your looking for something like echo $_POST['value']; ??

1 Comment

And yes I know about $_POST vars...but for some reason using this fancy jquery on the front-end with my multiselect - the variables are not being posted with the multiselect (it allows you to shift elements back and forth from one multiselect to another, then up/down to reorder - not your typical multiple select in plain HTML for my PHP to read...
0

You can use Jquery serialize to post all the data of the form including multi select

var submit_data = $('#output').serialize();
var post_data = submit_data ;
$.ajax({
    type: "POST",
    url: 'submitform.php',
    data: post_data,
    success: function(data)
    {
    }
});

You will get all the value in $_POST on submitform.php

Let me know it works for you

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.