
January 19th, 2004, 06:47 PM
|
|
|
|
Join Date: Apr 2007
Location: Charlottesville, VA USA
Posts: 425
Time spent in forums: < 1 sec
Reputation Power: 2
|
|
|
How to make an array in a html form
Well, I'm at a loss...
Here's the problem, any suggestions more than welcome... (thanks!)
I have an array of strings (PHP) that I want to display on my page. I also need to have the user be able to select any number of these strings by clicking the text, and I need to have access to a list of the selected items in both javascript and php. Hence, I want to have a hidden form field for each item, and I want this to be an array - so that I can iterate through it in javascript and later in php.
I have not been able to get this working. Can it be done? Ideally, an associative array, say "elementlist" with each index being one of the strings and the value being either "selected" or ""?
this is what I have
php Code:
Original
- php Code |
|
|
|
<? // $elements is my array of strings while (list($key, $value)= each ($elements)) { echo "<input type=hidden name=elementlist['$value']><SPAN onclick="selectitem (); ">$value</SPAN><BR>"; } ?>
the javascript : Quote: function selectitem()
{
elementlist['$value'].value='selected';
} | I just need to get to the point where I can access the elementlist[] array in javascript and have it passed as an array to php when the form is submitted. I was able to get the form to submit an array $_POST[elementlist] at one point but it won't do it anymore
Thanks for any input...
Peter
|