Jump to content


Photo

PHP, Arrays, and Javascript


  • Please log in to reply
5 replies to this topic

#1 cesarhtown

cesarhtown
  • Members
  • Pip
  • Newbie
  • 5 posts
  • LocationHouston

Posted 01 May 2006 - 07:43 PM

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.

#2 Zane

Zane
  • Administrators
  • Advanced Member
  • 4,134 posts

Posted 01 May 2006 - 07:48 PM

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?

btn_donate_SM.gif Want to thank me? Contribute to my PayPal piggy-bank
 

172938.png

#3 cesarhtown

cesarhtown
  • Members
  • Pip
  • Newbie
  • 5 posts
  • LocationHouston

Posted 01 May 2006 - 07:56 PM

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.

#4 Zane

Zane
  • Administrators
  • Advanced Member
  • 4,134 posts

Posted 01 May 2006 - 08:02 PM

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

btn_donate_SM.gif Want to thank me? Contribute to my PayPal piggy-bank
 

172938.png

#5 cesarhtown

cesarhtown
  • Members
  • Pip
  • Newbie
  • 5 posts
  • LocationHouston

Posted 01 May 2006 - 08:20 PM

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?

#6 Zane

Zane
  • Administrators
  • Advanced Member
  • 4,134 posts

Posted 01 May 2006 - 08:31 PM

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
if(isset($_POST['names']))
   $names = $_POST['names'];

btn_donate_SM.gif Want to thank me? Contribute to my PayPal piggy-bank
 

172938.png




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users