Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Extracting form info 2

Status
Not open for further replies.

skiflyer

Programmer
Joined
Sep 24, 2002
Messages
2,213
Location
US
I'm afraid this may be an HTML question but maybe not...

so here's what I have...
Code:
<select name=&quot;test1&quot; size=&quot;20&quot; multiple>
  <option value=&quot;1&quot;>One</option>
  <option value=&quot;2&quot;>Two</option>
</select>

within a posted form, then the page jsut does a 

echo &quot;<pre>&quot;;
print_r($_POST);
the problem is, I only get one of the selections if I highlight them both, any ideas how to fix this?

Thanks,
Rob
 
After all checkboxes I've used that on you'd think I would've thought of that. Thanks daniel!

Now to mix it with my javascript....

-Rob
 
Anyone know if there's another way to do this?

The problem is, javascript won't let me access a form element named

<select MULTIPLE name=&quot;test1[]&quot;>
...
</select>

but php doesn't seem to have the information if I do it without the []'s.

-Rob
 
In JavaScript you can access the array memebers like this:

CONTROL.options

You can check for
CONTROL.options.selected = true;
to see if it was selected. There is of course also a value:
CONTROL.options.value;

 
Oops - should have previewed this:

The markup removed the square brackets with the index:
You need:
Code:
CONTROL.options[i].selected = true;
 
Right, but CONTROL needs to be the name of the form element right?

So in my example, without the brackets I access

Code:
document.formname.test1.options[i].selected

however, I can't seem to access

document.formname.test1[].options[i].selected

Hmmm, now that gives me an idea...

-Rob
 
So that so pointed me in the wrong direction, but still to the solution (go figure).

The way I did it is quite simple...
Code:
<select MULTIPLE name=&quot;test1[]&quot; id=&quot;test1&quot;>
...
</select>



now because of the [] I can use the array in PHP and because of the id I can use javascript.  Thanks for the inspiration.
 
Yes, after limited testing in IE 6.0 and Mozilla 1.4a, I seem to be getting the best of both worlds, namely

Code:
document.formname.test1 in JavaScript and
$_POST[&quot;test1&quot;][]; in php
 
:)

It's great when the forums work like this...

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top