0

Ok guys i have this form

<input id="valor" name="valor[]" type="checkbox" value="1" />
<input id="valor" name="valor[]" type="checkbox" value="2" />
<input id="valor" name="valor[]" type="checkbox" value="3" />
<input id="valor" name="valor[]" type="checkbox" value="4" />
<input id="valor" name="valor[]" type="checkbox" value="5" />
<input id="valor" name="valor[]" type="checkbox" value="6" />

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

what i need is:

When i check any of the checkboxes an array with the format (for example)

1|2|4

is updated in real time inside the result text field, so i can use in php to explode i tryed a lot of thins none works

PS. just passing trough post will not be enough i know if i just post this field i gonna have an array but i need to pass to the result field

thanks in advance

1
  • 1
    if you explode in php you will also get an array, just like in post... maybe you just need to use your post array correctly? Commented May 4, 2013 at 23:18

1 Answer 1

1

You could easily execute a serialize() function on a form that wraps these checkboxes. The resulting string can be "decoded" in php using the parse_str() function.

A serialized string of all checkboxes being selected would look like this:

valor%5B%5D=1&valor%5B%5D=2&valor%5B%5D=3&valor%5B%5D=4&valor%5B%5D=5&valor%5B%5D=6

Passing that value though parse_str() will give you something similar to this:

[valor] => Array
    (
        [0] => 1
        [1] => 2
        [2] => 3
        [3] => 4
        [4] => 5
        [5] => 6
    )     
3
  • do u mind show me a example of that? Commented May 4, 2013 at 23:20
  • There isn't much to be shown... once your users have made their selection, execute a serialize() function on the checkbox elements - the resulting string should be passed through parse_str() once it reaches the server. Commented May 4, 2013 at 23:33
  • the problem is i have another fields in the form and i need the array only from the ckeckboxes any help? Commented May 5, 2013 at 0:01

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.