Connecting Tech Pros Worldwide Help | Site Map
 
 
LinkBack Thread Tools Search this Thread
  #1  
Old July 17th, 2005, 03:55 AM
Ramses van Pinxteren
Guest
 
Posts: n/a
Default Php/Javascript problems with multiple select

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.

HELP MEEEEEEE :)

Greetz,
Ramses




  #2  
Old July 17th, 2005, 03:55 AM
ozias
Guest
 
Posts: n/a
Default 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]


  #3  
Old July 17th, 2005, 03:56 AM
Daniel Tryba
Guest
 
Posts: n/a
Default Re: Php/Javascript problems with multiple select

Ramses van Pinxteren <ramsesvp@nospan.quicknet.nl> wrote:[color=blue]
> 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 :'([/color]

You are incorrect. Javascript has no problem with elements named like
'userid[]', us the element name in the elements hash.

--

Daniel Tryba

  #4  
Old July 17th, 2005, 03:56 AM
R. Rajesh Jeba Anbiah
Guest
 
Posts: n/a
Default Re: Php/Javascript problems with multiple select

Ramses van Pinxteren <ramsesvp@NOSPAN.quicknet.nl> wrote in message news:<efb27$401ff994$52d9b2ca$29655@news.multikabe l.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 :'([/color]

Read further. It has an answer.
<http://in2.php.net/manual/en/faq.html.php#faq.html.select-multiple>

--
"Success = 10% sweat + 90% tears"
Email: rrjanbiah-at-Y!com
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 205,414 network members.