Re: [PHP] Multiple selections

2002-11-13 Thread David Rice
Thanks Mike and Ernest for the info on how to handle the "var[]" 
Multiple Select name more sensibly in JavaScript.

Not even a workaround.  By definition, in JavaScript x.y is identical 
to x['y'], so where for a simple field you might write:

  document.formname.myvar.value

for a field named "myvar[]" you can write:

  document.formname['myvar[]'].value

Cheers-
David


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




RE: [PHP] Multiple selections

2002-11-13 Thread Ford, Mike [LSS]
> -Original Message-
> From: Ernest E Vogelsinger [mailto:ernest@;vogelsinger.at]
> Sent: 13 November 2002 07:34
> To: David Rice
> 
> I've made quite a number of JavaScripts controlled PHP 
> dialogs containing
> the [], they all work like a charm. There's only one thing 
> you cannot do AFAIK:
>myform.myvar[].value = 0;

 myform['myvar[]'].value = 0;

Cheers!

Mike

-
Mike Ford,  Electronic Information Services Adviser,
Learning Support Services, Learning & Information Services,
JG125, James Graham Building, Leeds Metropolitan University,
Beckett Park, LEEDS,  LS6 3QS,  United Kingdom
Email: [EMAIL PROTECTED]
Tel: +44 113 283 2600 extn 4730  Fax:  +44 113 283 3211 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




RE: [PHP] Multiple selections

2002-11-13 Thread Ford, Mike [LSS]
> -Original Message-
> From: David Rice [mailto:davidrice@;rogers.com]
> Sent: 13 November 2002 01:00
> 
> On Tuesday, November 12, 2002, at 07:34 PM, Ernest E 
> Vogelsinger wrote:
> >
> > Sure it is - just name the listbox control "myvar[]" (note the angle
> > brackets). PHP will recognize this being an array, and 
> you'll end up 
> > with
> > $myvar = array('select1','select2');
> 
> Is this the only way to do this?

Yes.
 
> I just had to do some work with JavaScript and forms and the 
> "myvar[]" 
> name clobbered JavaScript's access to form elements by name. I had to 
> do some ugly form.elements[x] looping to get at the "myvar[]" control.
> 
> This kind on external language hostility is not that cool, especially 
> toward such a common language as JavaScript.
> 
> My apologies to PHP if the language provides a workaround :)

Not even a workaround.  By definition, in JavaScript x.y is identical to x['y'], so 
where for a simple field you might write:

  document.formname.myvar.value

for a field named "myvar[]" you can write:

  document.formname['myvar[]'].value


Cheers!

Mike

-
Mike Ford,  Electronic Information Services Adviser,
Learning Support Services, Learning & Information Services,
JG125, James Graham Building, Leeds Metropolitan University,
Beckett Park, LEEDS,  LS6 3QS,  United Kingdom
Email: [EMAIL PROTECTED]
Tel: +44 113 283 2600 extn 4730  Fax:  +44 113 283 3211 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] Multiple selections

2002-11-12 Thread Ernest E Vogelsinger
At 02:06 13.11.2002, Todd Cary said:
[snip] 
>Many thanks!!  One thing I do not understand in the "types" of variables
>is the use and referencing of a variable with the "[]".  What I usually do
>is define a variable as
>
>$myvar = array();
>
>And then I use the "[]" to refer to the elements.  However, if I
>understand you suggestion, which works like a champ, the use of the "[]"
>tells the interpreter to treat $myvar as an array.
---[snip] 

No. The '[]' doesn't have to do with a PHP variable, it only tells PHP to
treat an _incoming_ parameter as an array.

What happens when PHP parses form data is something like:

variable is named "name"[] ?
   yes - $_REFERENCE['name'] = array(v1, v2, v3);
   no  - $_REFERENCE['name'] ? v1;


-- 
   >O Ernest E. Vogelsinger
   (\)ICQ #13394035
^ http://www.vogelsinger.at/



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] Multiple selections

2002-11-12 Thread Ernest E Vogelsinger
At 01:59 13.11.2002, David Rice said:
[snip]
>On Tuesday, November 12, 2002, at 07:34 PM, Ernest E Vogelsinger wrote:
>>
>> Sure it is - just name the listbox control "myvar[]" (note the angle
>> brackets). PHP will recognize this being an array, and you'll end up 
>> with
>> $myvar = array('select1','select2');
>
>Is this the only way to do this?

As to my knowledge it is the only way.

>I just had to do some work with JavaScript and forms and the "myvar[]" 
>name clobbered JavaScript's access to form elements by name. I had to 
>do some ugly form.elements[x] looping to get at the "myvar[]" control.

I believe you can do this in JavaScript:

hf = form('myform');
he = hf.elements['myselect[]');

to get a handle to the form element.

>This kind on external language hostility is not that cool, especially 
>toward such a common language as JavaScript.

I've made quite a number of JavaScripts controlled PHP dialogs containing
the [], they all work like a charm. There's only one thing you cannot do AFAIK:
   myform.myvar[].value = 0;


-- 
   >O Ernest E. Vogelsinger
   (\)ICQ #13394035
^ http://www.vogelsinger.at/



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] Multiple selections

2002-11-12 Thread Todd Cary
David -

Speaking of JavaScript, is there a way to block the Enter key?  If I 
have two buttons, the Enter key always pushes the one with focus.

What is the accepted way to handle this?  With one button it is nice to 
let the user press the Enter key and depress the one button - with two, 
it can be a problem.

Todd

David Rice wrote:

On Tuesday, November 12, 2002, at 07:34 PM, Ernest E Vogelsinger wrote:



Sure it is - just name the listbox control "myvar[]" (note the angle
brackets). PHP will recognize this being an array, and you'll end up 
with
$myvar = array('select1','select2');


Is this the only way to do this?

I just had to do some work with JavaScript and forms and the "myvar[]" 
name clobbered JavaScript's access to form elements by name. I had to 
do some ugly form.elements[x] looping to get at the "myvar[]" control.

This kind on external language hostility is not that cool, especially 
toward such a common language as JavaScript.

My apologies to PHP if the language provides a workaround :)

David




--
Ariste Software, Petaluma, CA 94952




Re: [PHP] Multiple selections

2002-11-12 Thread David Rice
On Tuesday, November 12, 2002, at 07:34 PM, Ernest E Vogelsinger wrote:


Sure it is - just name the listbox control "myvar[]" (note the angle
brackets). PHP will recognize this being an array, and you'll end up 
with
$myvar = array('select1','select2');

Is this the only way to do this?

I just had to do some work with JavaScript and forms and the "myvar[]" 
name clobbered JavaScript's access to form elements by name. I had to 
do some ugly form.elements[x] looping to get at the "myvar[]" control.

This kind on external language hostility is not that cool, especially 
toward such a common language as JavaScript.

My apologies to PHP if the language provides a workaround :)

David



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Multiple selections

2002-11-12 Thread Todd Cary




Many thanks!!  One thing I do not understand in the "types" of variables
is the use and referencing of a variable with the "[]".  What I usually do
is define a variable as

$myvar = array();

And then I use the "[]" to refer to the elements.  However, if I understand
you suggestion, which works like a champ, the use of the "[]" tells the interpreter
to treat $myvar as an array.

Todd

Marco Tabini wrote:

  Sure! Just add [] to the end of the name of the field. PHP will return
all the values in an array:




Marco
  
  
  
  

  

Subject:

[PHP] Multiple selections
  
  

From: 
Todd Cary <[EMAIL PROTECTED]>
  
  

Date: 
Tue, 12 Nov 2002 16:37:43 -0800
  
  

To: 
"[EMAIL PROTECTED]" <[EMAIL PROTECTED]>
  

  
  
 I have a pull-down with the MULTIPLE attribute.  If the Form is of Type
 GET and two values are selected (e.g. select1 and select2), I see in the
 URL the following: 
 
?myvar=select1&myvar=select2 
 
"myvar" appears twice, however, if I check the $HTTP_GET_VARS, I only  have
one value: myvar=select2. 
 
Is it possible to get both values? 
 
Todd 
 
 


-- 
 

  
 
 
 





Re: [PHP] Multiple selections

2002-11-12 Thread Marco Tabini
Sure! Just add [] to the end of the name of the field. PHP will return
all the values in an array:




Marco
-- 

php|architect - The magazine for PHP Professionals
The monthly worldwide magazine dedicated to PHP programmers

Come visit us at http://www.phparch.com!

--- Begin Message ---
I have a pull-down with the MULTIPLE attribute.  If the Form is of Type 
GET and two values are selected (e.g. select1 and select2), I see in the 
URL the following:

?myvar=select1&myvar=select2

"myvar" appears twice, however, if I check the $HTTP_GET_VARS, I only 
have one value: myvar=select2.

Is it possible to get both values?

Todd


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


--- End Message ---
-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] Multiple selections

2002-11-12 Thread Ernest E Vogelsinger
At 01:37 13.11.2002, Todd Cary said:
[snip]
>I have a pull-down with the MULTIPLE attribute.  If the Form is of Type 
>GET and two values are selected (e.g. select1 and select2), I see in the 
>URL the following:
>
>?myvar=select1&myvar=select2
>
>"myvar" appears twice, however, if I check the $HTTP_GET_VARS, I only 
>have one value: myvar=select2.
>
>Is it possible to get both values?
[snip] 

Sure it is - just name the listbox control "myvar[]" (note the angle
brackets). PHP will recognize this being an array, and you'll end up with
$myvar = array('select1','select2');


-- 
   >O Ernest E. Vogelsinger
   (\)ICQ #13394035
^ http://www.vogelsinger.at/



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] multiple selections in list/menu field

2001-09-14 Thread Richard Baskett

I didn't take the time to read your code too thoroughly, but remember to
have your select name to be anything with "[]" at the end of it, from the
look of your name field you have something inside the [], you need to get
rid of the rec_pd4 and just call it "x[]" or whatever you would like to call
it as long as the "[]" is empty :)  I hope that made sense!

Rick

> From: Tom Beidler <[EMAIL PROTECTED]>
> Date: Fri, 14 Sep 2001 17:26:50 -0700
> To: php list <[EMAIL PROTECTED]>
> Subject: [PHP] multiple selections in list/menu field
> 
> I'm trying to use a list/menu field with multiple options allowed but I'm
> only getting the very last selection.
> 
> Here's part of my code to build the list/menu field;
> 
> print ("\n");
> print ("$option_pd4");
> print ("   \n");
> 
> Here's the code to build the options;
> 
> $pd4arry = array(array("c1,","Bookpacks & Daypacks"),array("c2,","Mini
> Packs/Diaper Bag"),array("c3,","Shoulder Bags/Briefcase"));
> foreach($pd4arry as $value) {
> 
>   if (($value[0] == $category_code) || ($value[0] == $x[rec_pd4])) {
>   $option_pd4 .= "   value=\"$value[0]\"selected>$value[1]\n";
>   } else {
>   $option_pd4 .= "   value=\"$value[0]\">$value[1]\n";
>   }
> }
> 
> The field displays fine but I only get the last option. I'm testing with IE
> 5.
> 
> Let me know if this is not a PHP issue but I thought there might be
> something that would prevent me from using this type of field with PHP.
> 
> Thanks,
> Tom
> 
> 
> -- 
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> To contact the list administrators, e-mail: [EMAIL PROTECTED]
> 


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] Multiple Selections?

2001-05-13 Thread Sean Cazzell

> I have a Multiple Selection HTML Field --- the user can select any number of
> items by holding down the CTRL key.  When I submit my form to my (say)
> TestProg.php -- in the Hidden Input Field I only see the value for the
> *last* item I selected... how can I see all the items I selected?

If you want to allow the user to select multiple items, you should append
'[]' to the end of the name of your select.



Now when you get the value, it will be an array of the items they
selected.

You may run into a problem with your hidden input type on the second page
- I'm not sure how PHP will handle things because your value will now be
an array.  You may want to write out a hidden field for each of the users
selections - like:






Regards,

Sean

On Sun, 13 May 2001, Jason Caldwell wrote:

> 
> Thanks.
> Jason
> 
> 
> 
> -- 
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> To contact the list administrators, e-mail: [EMAIL PROTECTED]
> 


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]