Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Multiple Select list help
Old 10-13-2010, 01:57 AM Multiple Select list help
Skilled Talker

Posts: 64
Name: Ralph Freshour
Trades: 0
I have a Select tag on my php form named my_form.php:


PHP Code:
<FORM NAME="my_form" ACTION="my_dispatcher.php" METHOD="post"
<
SELECT NAME="frm_available_depts_cbo[]" MULTIPLE='multiple' SIZE="8"
my_form.php calls my_dispatcher.php and I'm trying to access the items in the list like this:


PHP Code:
foreach ($frm_available_depts_cbo as $dept_id
        { 
          print 
"$dept_id<br>"
        } 
But I'm getting: Warning: Invalid argument supplied for foreach()

I'm submitting my_form.php using javascript's .Submit() in a JS function:

PHP Code:
// JS code 
 
function submit_my_form_click() 

  
// do other stuff here before submitting ... 
  
document.my_form.submit(); 


<
INPUT NAME="btn_click" TYPE="button" VALUE="Update" onClick="submit_myform_click();"
So, I can't figure out why I'm getting that warning!
__________________
RalphF
Business Text Messaging Services

Please login or register to view this content. Registration is FREE
rfresh is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 10-13-2010, 02:00 AM Re: Multiple Select list help
NullPointer's Avatar
Will Code for Food

Posts: 2,815
Name: Matt
Location: Irvine, CA
Trades: 0
Check the post data.
PHP Code:
print_r($_POST); 
Also, are you setting $frm_available_depts_cbo? If register globals is off (which it should be) you have to set it:
PHP Code:
$frm_available_depts_cbo $_POST['frm_available_depts_cbo']; 
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
NullPointer is offline
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Old 10-13-2010, 02:32 AM Re: Multiple Select list help
Skilled Talker

Posts: 64
Name: Ralph Freshour
Trades: 0
print_r($_POST);

displays the first value of the Select list.
There are 3 items in the frm_available_depts_cbo[] list var but only the 1st one displays when I do the print_r

var_dump($frm_available_depts_cbo);
displays:
string(2) "66"
66 is the value of the first item in the list but there are more items. I don't know what the string(2) means.


__________________
RalphF
Business Text Messaging Services

Please login or register to view this content. Registration is FREE

Last edited by rfresh; 10-13-2010 at 02:47 AM..
rfresh is offline
Reply With Quote
View Public Profile
 
Old 10-13-2010, 05:21 AM Re: Multiple Select list help
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,384
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
It's because name="name[]" does NOT return the items as an array.

Multiple selections are returned as a comma separated string.
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 10-13-2010, 09:52 AM Re: Multiple Select list help
Skilled Talker

Posts: 64
Name: Ralph Freshour
Trades: 0
I have 4 items in the list and the following only displays one item because the count is only 1, not 4:

PHP Code:
$php_string explode(",",$frm_available_depts_cbo);
print 
count($php_string)."<br>";
for (
$i 0$i count($php_string); $i++)
    {
      print 
$php_string[$i]."<br>";
    } 
__________________
RalphF
Business Text Messaging Services

Please login or register to view this content. Registration is FREE
rfresh is offline
Reply With Quote
View Public Profile
 
Old 10-13-2010, 10:14 AM Re: Multiple Select list help
Skilled Talker

Posts: 64
Name: Ralph Freshour
Trades: 0
I discovered the problem is being caused by my JS code just prior to the JS submit. If I remm out the JS code then the frm_available_depts_cbo var works as expected. I was trying to use JS to move selected list items from one list to the other.

PHP Code:
var selectAssignedOptions document.getElementById('id_assigned_to_emp_depts_cbo').options;
var 
selectAvailableOptions document.getElementById('id_available_depts_cbo').options;
var 
AssignedOption;
var 
0;
for (
selectAvailableOptions.length-1>= 0i--)
      {
        if (
selectAvailableOptions[i].selected)
           {
             
AssignedOption document.createElement("Option");
             
AssignedOption.text selectAvailableOptions[i].text;
             
AssignedOption.value selectAvailableOptions[i].value;
             
selectAssignedOptions.add(AssignedOption);
             
selectAvailableOptions.remove(i);
           }
      }
  
document.my_form.submit(); 
So, something in my JS is trashing my form's frm_available_depts_cbo var.
__________________
RalphF
Business Text Messaging Services

Please login or register to view this content. Registration is FREE
rfresh is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Multiple Select list help
 

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 On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.25300 seconds with 12 queries