Jump to content

Archived

This topic is now archived and is closed to further replies.

cesarhtown

PHP, Arrays, and Javascript

Recommended Posts

Hello all. I need some help with some javascript using php.

*I have a list in a <select></select> with 5 different <option>'s.
**Now, I wish to select 1, 2, or more of those 5 options and have a button next to the box that says "CREATE ARRAY".
***When I click on CREATE ARRAY, I want to create a PHP array onclick, in other words storing those selections into an array. Any ideas?

Please help.

Cesar.

Share this post


Link to post
Share on other sites
do want it to actually create an inline usuable array that you could use after the select box

or are you looking for the button to just create PHP code for you to copy and paste somewhere?

Share this post


Link to post
Share on other sites
I would like to put my selections into an array called $names or something like that. I would like to have it in an array to manipulate the data somewhere else later on.

Share this post


Link to post
Share on other sites
I'm pretty sure this isn't possible in PHP, unless you refreshed the page when they pushed the button
but it could be done in AJAX, but you're array would be of Javascript rather than PHP

Share this post


Link to post
Share on other sites
Ok, so lets assume that the page is refreshed. Now after clicking on the button, what is the procedure to put those selections in an array on Php?

Share this post


Link to post
Share on other sites
set the name of the selection box to an array like

<select name="names[]">
...
</select>

and put that along with your Create button in a form


set the form to POST or GET to the same page

then at the top of you're page check for that POST or GET value and create an array from that

E.G
[code]if(isset($_POST['names']))
   $names = $_POST['names'];
[/code]

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.