Re: Php/Javascript problems with multiple select
"Ramses van Pinxteren" <ramsesvp@NOSPAN.quicknet.nl> wrote in message
news:efb27$401ff994$52d9b2ca$29655@news.multikabel .nl...[color=blue]
> hello,
>
> I have a PHP/Javascript problem. If I want to make a multiple select
> like this one:
>
> $html .= "<td><select name='userid' onChange='changeuserinfo()' multiple
> size='10'>";
> $html .= "<option value=''>Selecteer user</option>";
> $html .= "<option value='1'>user 1</option>";
> $html .= "<option value='2'>user 2</option>";
> $html .= "<option value='3'>user 3</option>";
> $html .= "<option value='4'>user 4</option>";
> $html .= "<option value='5'>user 5</option>";
> $html .= "<option value='6'>user 6</option>";
> $html .= "</select>";
> $html .= "</td>";
>
> I can read this one out with javascript but accourding tot the PHP
> manual I have to declare the select as follows to read it out in php:
> $html .= "<td><select name='userid[]' multiple size='10'>";
> and this is something that javascript does not want to swallow :'(
>
> How can i make it so that both javascript and php can access the fields
> and do their usefull stuff with it.
>[/color]
<select id="userid[]" name="userid[]" onchange="changeuserinfo();">
and in the javascript use
FormObject=document.forms['name of form'];
SelectObject=FormObject.elements['userid[]'];
you can then loop through the array SelectObject.options[], checking the
'selected' property to see which items have been selected
SelectionCount=0;
for(n=0;n<SelectObject.options.length;n++)
{
if(SelectObject.options[n].selected)
{
// option selected
SelectionCount++;
}
else
{
// option not selected
}
}
The SelectObject.selectedindex property only shows the first selected
element.
[color=blue]
> HELP MEEEEEEE :)
>
> Greetz,
> Ramses
>[/color] |