php-general Digest 8 Dec 2009 11:45:23 -0000 Issue 6476

Topics (messages 300287 through 300304):

Re: mysterious include problem
        300287 by: Kim Madsen
        300288 by: Ashley Sheridan
        300289 by: LinuxManMikeC

Re: Live PHP Code Templates for NetBeans - accelerate your php development.
        300290 by: German Geek
        300301 by: Raymond Irving

cookies and carts
        300291 by: Allen McCabe
        300292 by: Ashley Sheridan
        300293 by: Philip Thompson
        300294 by: Philip Thompson
        300295 by: Ashley Sheridan
        300296 by: Philip Thompson
        300297 by: Ashley Sheridan
        300303 by: Paul M Foster

Passing HTML array index to JS?
        300298 by: Skip Evans
        300299 by: Philip Thompson
        300300 by: Skip Evans
        300302 by: Philip Thompson

request for support
        300304 by: Tarek Kaddoura

Administrivia:

To subscribe to the digest, e-mail:
        [email protected]

To unsubscribe from the digest, e-mail:
        [email protected]

To post to the list, e-mail:
        [email protected]


----------------------------------------------------------------------
--- Begin Message ---
Hi Allen

Allen McCabe wrote on 2009-12-07 21:03:
I have been using includes for my content for a while now with no problems.
Suddenly it has stopped working, and it may or may not be from some changes
I made in my code structure.

I use default.php for most or all of my pages within a given directory,
changing the content via page numbers in the query string.


So on default.php, I have the following code:


<?php
if(isset($_GET['page']))
{
  $thispage = $_GET['page'];
  $content = 'content/'.$_GET['page'].'.inc';
}
> else
> {
>   $thispage = "default";
>   $content = 'content/default.inc';
> }

WOUW! this is a potential security issue!

I can add _any_ parameter to page, incl. an external one, so skip this and use a switch instead

switch($_GET['page']) {
  case "admin": $content = "content/admin.inc"; break;
  case "member": $content = "content/member.inc"; break;
  default: $content = "content/default.inc";
}

What use is $thispage by the way?

?>
<html>, <body>, <div> etc.
<?php include($content); ?>


I have a content subdirectory where I store all the pages with files such as
"default.inc, 101.inc, 102.inc, etc.

As I said, this has been working fine up until now, if I use the url
"user/default.php" or just "user/" I get this error:


*Warning*: include(content/.inc)

$_GET['page'] is not set, try and print it to the screen aswell...

[function.include<http://lpacmarketing.hostzi.com/user/function.include>]:
failed to open stream: No such file or directory in *
/home/a9066165/public_html/user/default.php* on line *89*

AND

*Warning*: include()
[function.include<http://lpacmarketing.hostzi.com/user/function.include>]:
Failed opening 'content/.inc' for inclusion
(include_path='.:/usr/lib/php:/usr/local/lib/php') in *
/home/a9066165/public_html/user/default.php* on line *89*

But if I use "user/default.php?page=default"  I get the correct content.

It's acting as if page is set, but set to NULL, and then trying to find an
include at path "content/.inc"  what's going on??



--
Kind regards
Kim Emax - masterminds.dk

--- End Message ---
--- Begin Message ---
On Mon, 2009-12-07 at 21:14 +0100, Kim Madsen wrote:

> Hi Allen
> 
> Allen McCabe wrote on 2009-12-07 21:03:
> > I have been using includes for my content for a while now with no problems.
> > Suddenly it has stopped working, and it may or may not be from some changes
> > I made in my code structure.
> > 
> > I use default.php for most or all of my pages within a given directory,
> > changing the content via page numbers in the query string.
> > 
> > 
> > So on default.php, I have the following code:
> > 
> > 
> > <?php
> > if(isset($_GET['page']))
> > {
> >   $thispage = $_GET['page'];
> >   $content = 'content/'.$_GET['page'].'.inc';
> > }
>  > else
>  > {
>  >   $thispage = "default";
>  >   $content = 'content/default.inc';
>  > }
> 
> WOUW! this is a potential security issue!
> 
> I can add _any_ parameter to page, incl. an external one, so skip this 
> and use a switch instead
> 
> switch($_GET['page']) {
>    case "admin": $content = "content/admin.inc"; break;
>    case "member": $content = "content/member.inc"; break;
>    default: $content = "content/default.inc";
> }
> 
> What use is $thispage by the way?
> 
> > ?>
> > <html>, <body>, <div> etc.
> > <?php include($content); ?>
> > 
> > 
> > I have a content subdirectory where I store all the pages with files such as
> > "default.inc, 101.inc, 102.inc, etc.
> > 
> > As I said, this has been working fine up until now, if I use the url
> > "user/default.php" or just "user/" I get this error:
> > 
> > 
> > *Warning*: include(content/.inc)
> 
> $_GET['page'] is not set, try and print it to the screen aswell...
> 
> > [function.include<http://lpacmarketing.hostzi.com/user/function.include>]:
> > failed to open stream: No such file or directory in *
> > /home/a9066165/public_html/user/default.php* on line *89*
> > 
> > AND
> > 
> > *Warning*: include()
> > [function.include<http://lpacmarketing.hostzi.com/user/function.include>]:
> > Failed opening 'content/.inc' for inclusion
> > (include_path='.:/usr/lib/php:/usr/local/lib/php') in *
> > /home/a9066165/public_html/user/default.php* on line *89*
> > 
> > But if I use "user/default.php?page=default"  I get the correct content.
> > 
> > It's acting as if page is set, but set to NULL, and then trying to find an
> > include at path "content/.inc"  what's going on??
> > 
> 
> 
> -- 
> Kind regards
> Kim Emax - masterminds.dk
> 


Are you sure that the paths are correct, including relative ones?

Thanks,
Ash
http://www.ashleysheridan.co.uk



--- End Message ---
--- Begin Message ---
Instead of hard coding cases you can validate and constrain the input
with a regex.  Much more flexible when adding content.  I would also
add code to make sure the file exists, otherwise fall through to the
default.

On Mon, Dec 7, 2009 at 1:14 PM, Kim Madsen <[email protected]> wrote:
> Hi Allen
>
> Allen McCabe wrote on 2009-12-07 21:03:
>>
>> I have been using includes for my content for a while now with no
>> problems.
>> Suddenly it has stopped working, and it may or may not be from some
>> changes
>> I made in my code structure.
>>
>> I use default.php for most or all of my pages within a given directory,
>> changing the content via page numbers in the query string.
>>
>>
>> So on default.php, I have the following code:
>>
>>
>> <?php
>> if(isset($_GET['page']))
>> {
>>  $thispage = $_GET['page'];
>>  $content = 'content/'.$_GET['page'].'.inc';
>> }
>
>> else
>> {
>>   $thispage = "default";
>>   $content = 'content/default.inc';
>> }
>
> WOUW! this is a potential security issue!
>
> I can add _any_ parameter to page, incl. an external one, so skip this and
> use a switch instead
>
> switch($_GET['page']) {
>  case "admin": $content = "content/admin.inc"; break;
>  case "member": $content = "content/member.inc"; break;
>  default: $content = "content/default.inc";
> }
>
> What use is $thispage by the way?
>
>> ?>
>> <html>, <body>, <div> etc.
>> <?php include($content); ?>
>>
>>
>> I have a content subdirectory where I store all the pages with files such
>> as
>> "default.inc, 101.inc, 102.inc, etc.
>>
>> As I said, this has been working fine up until now, if I use the url
>> "user/default.php" or just "user/" I get this error:
>>
>>
>> *Warning*: include(content/.inc)
>
> $_GET['page'] is not set, try and print it to the screen aswell...
>
>> [function.include<http://lpacmarketing.hostzi.com/user/function.include>]:
>> failed to open stream: No such file or directory in *
>> /home/a9066165/public_html/user/default.php* on line *89*
>>
>> AND
>>
>> *Warning*: include()
>> [function.include<http://lpacmarketing.hostzi.com/user/function.include>]:
>> Failed opening 'content/.inc' for inclusion
>> (include_path='.:/usr/lib/php:/usr/local/lib/php') in *
>> /home/a9066165/public_html/user/default.php* on line *89*
>>
>> But if I use "user/default.php?page=default"  I get the correct content.
>>
>> It's acting as if page is set, but set to NULL, and then trying to find an
>> include at path "content/.inc"  what's going on??
>>
>
>
> --
> Kind regards
> Kim Emax - masterminds.dk
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

--- End Message ---
--- Begin Message ---
Hi, I would like to check this out. How do you enable these code templates
in NetBeans?

2009/12/8 Raymond Irving <[email protected]>

> Hello Everyone,
>
> I've made a few code templates (HTML, PHP)  available for everyone to
> download and use with NetBeans 6.7 or higher. It will greatly
> accelerate your php development.
>
>
> http://code.google.com/p/raxan/downloads/detail?name=code-templates.zip&can=2&q=
>
> And if your interested in further accelerating your PHP/Ajax
> development, then you might want to check out the new and improved
> Raxan for PHP (http://raxanpdi.com/)
>
> __
> Raymond Irving
> Raxan for PHP - Ajax just got a whole lot easier!
>

--- End Message ---
--- Begin Message ---
You can import the templates by going to Tools > Options > Code Templates then 
click on the "Import" button at the bottom of the window.

To use the templates: 

1. Create or open an HTML page
2. Enter the name name of the template then press the "Tab" key on the keyboard.


Best regards,
__
Raymond Irving
Raxan for PHP - Building Rich Applications one Page at a Time




________________________________
From: German Geek <[email protected]>
To: Raymond Irving <[email protected]>
Cc: PHP-General List <[email protected]>
Sent: Mon, December 7, 2009 5:16:04 PM
Subject: Re: [PHP] Live PHP Code Templates for NetBeans - accelerate your php  
development.

Hi, I would like to check this out. How do you enable these code templates in 
NetBeans?


2009/12/8 Raymond Irving <[email protected]>

Hello Everyone,
>
>>I've made a few code templates (HTML, PHP)  available for everyone to
>>download and use with NetBeans 6.7 or higher. It will greatly
>>accelerate your php development.
>
>http://code.google.com/p/raxan/downloads/detail?name=code-templates.zip&can=2&q=
>
>>And if your interested in further accelerating your PHP/Ajax
>>development, then you might want to check out the new and improved
>>Raxan for PHP (http://raxanpdi.com/)
>
>>__
>Raymond Irving
>>Raxan for PHP - Ajax just got a whole lot easier!
>

--- End Message ---
--- Begin Message ---
I have a shopping cart type system set up which keeps track of the cart
contents using a SESSION variable, where $_SESSION['cart'][$item_id'] is
equal to the quantity, so the name/value pair is all the information I need.

But sessions are unreliable on the free server I am currently using for this
website (not my choice), so I had start using cookies because users were
being sporadically logged out, sometimes just on a page refresh.

I want to find a way to set a cookie to remember the cart items as well, and
I thought setting a cookie for each item/quantity pair was the way to go
until I started trying to figure out how to unset all those cookies if the
user empties their cart.

Is there any way to set cookies with an array for the name? Intead of
$_COOKIE['item_number'] have $_COOKIE['cart']['item_number'] like I have the
SESSION?

--- End Message ---
--- Begin Message ---
On Mon, 2009-12-07 at 14:39 -0800, Allen McCabe wrote:

> I have a shopping cart type system set up which keeps track of the cart
> contents using a SESSION variable, where $_SESSION['cart'][$item_id'] is
> equal to the quantity, so the name/value pair is all the information I need.
> 
> But sessions are unreliable on the free server I am currently using for this
> website (not my choice), so I had start using cookies because users were
> being sporadically logged out, sometimes just on a page refresh.
> 
> I want to find a way to set a cookie to remember the cart items as well, and
> I thought setting a cookie for each item/quantity pair was the way to go
> until I started trying to figure out how to unset all those cookies if the
> user empties their cart.
> 
> Is there any way to set cookies with an array for the name? Intead of
> $_COOKIE['item_number'] have $_COOKIE['cart']['item_number'] like I have the
> SESSION?


What about storing a unique ID in the cookie, and matching it up with
information for that user in a database. It's sort of simulating a
sessions, but without the session handler getting involved, which looks
slightly messed up from what you've said.

Thanks,
Ash
http://www.ashleysheridan.co.uk



--- End Message ---
--- Begin Message ---
On Dec 7, 2009, at 4:39 PM, Allen McCabe wrote:

> I have a shopping cart type system set up which keeps track of the cart
> contents using a SESSION variable, where $_SESSION['cart'][$item_id'] is
> equal to the quantity, so the name/value pair is all the information I need.
> 
> But sessions are unreliable on the free server I am currently using for this
> website (not my choice), so I had start using cookies because users were
> being sporadically logged out, sometimes just on a page refresh.
> 
> I want to find a way to set a cookie to remember the cart items as well, and
> I thought setting a cookie for each item/quantity pair was the way to go
> until I started trying to figure out how to unset all those cookies if the
> user empties their cart.
> 
> Is there any way to set cookies with an array for the name? Intead of
> $_COOKIE['item_number'] have $_COOKIE['cart']['item_number'] like I have the
> SESSION?

Don't do it this way. At some point (don't know if it's still true), IE had a 
limit of 20 cookies per domain - this includes cookie arrays. The proper way to 
do this would be to hold some sort of key in a cookie:

user_cart = 'some unique value for this user'

Then, in your PHP code, grab the value of $_COOKIE['user_cart'] to reference 
data in a database. Then, you pull the information from the database with this 
unique key and use it to display the appropriate items. This is the most secure 
way to do it (with the proper security measures ;) and it doesn't put 100's of 
needless cookies on the user's machine.

Hope this helps.
~Philip

--- End Message ---
--- Begin Message ---
On Dec 7, 2009, at 4:40 PM, Ashley Sheridan wrote:

> On Mon, 2009-12-07 at 14:39 -0800, Allen McCabe wrote:
> 
>> I have a shopping cart type system set up which keeps track of the cart
>> contents using a SESSION variable, where $_SESSION['cart'][$item_id'] is
>> equal to the quantity, so the name/value pair is all the information I need.
>> 
>> But sessions are unreliable on the free server I am currently using for this
>> website (not my choice), so I had start using cookies because users were
>> being sporadically logged out, sometimes just on a page refresh.
>> 
>> I want to find a way to set a cookie to remember the cart items as well, and
>> I thought setting a cookie for each item/quantity pair was the way to go
>> until I started trying to figure out how to unset all those cookies if the
>> user empties their cart.
>> 
>> Is there any way to set cookies with an array for the name? Intead of
>> $_COOKIE['item_number'] have $_COOKIE['cart']['item_number'] like I have the
>> SESSION?
> 
> 
> What about storing a unique ID in the cookie, and matching it up with
> information for that user in a database. It's sort of simulating a
> sessions, but without the session handler getting involved, which looks
> slightly messed up from what you've said.
> 
> Thanks,
> Ash
> http://www.ashleysheridan.co.uk

Blast your speedier typing!! =P

~Philip


--- End Message ---
--- Begin Message ---
On Mon, 2009-12-07 at 16:48 -0600, Philip Thompson wrote:

> On Dec 7, 2009, at 4:40 PM, Ashley Sheridan wrote:
> 
> > On Mon, 2009-12-07 at 14:39 -0800, Allen McCabe wrote:
> > 
> >> I have a shopping cart type system set up which keeps track of the cart
> >> contents using a SESSION variable, where $_SESSION['cart'][$item_id'] is
> >> equal to the quantity, so the name/value pair is all the information I 
> >> need.
> >> 
> >> But sessions are unreliable on the free server I am currently using for 
> >> this
> >> website (not my choice), so I had start using cookies because users were
> >> being sporadically logged out, sometimes just on a page refresh.
> >> 
> >> I want to find a way to set a cookie to remember the cart items as well, 
> >> and
> >> I thought setting a cookie for each item/quantity pair was the way to go
> >> until I started trying to figure out how to unset all those cookies if the
> >> user empties their cart.
> >> 
> >> Is there any way to set cookies with an array for the name? Intead of
> >> $_COOKIE['item_number'] have $_COOKIE['cart']['item_number'] like I have 
> >> the
> >> SESSION?
> > 
> > 
> > What about storing a unique ID in the cookie, and matching it up with
> > information for that user in a database. It's sort of simulating a
> > sessions, but without the session handler getting involved, which looks
> > slightly messed up from what you've said.
> > 
> > Thanks,
> > Ash
> > http://www.ashleysheridan.co.uk
> 
> Blast your speedier typing!! =P
> 
> ~Philip
> 


By the power of Kenco!

Thanks,
Ash
http://www.ashleysheridan.co.uk



--- End Message ---
--- Begin Message ---
On Dec 7, 2009, at 4:46 PM, Ashley Sheridan wrote:

> On Mon, 2009-12-07 at 16:48 -0600, Philip Thompson wrote:
>> 
>> On Dec 7, 2009, at 4:40 PM, Ashley Sheridan wrote:
>> 
>> > On Mon, 2009-12-07 at 14:39 -0800, Allen McCabe wrote:
>> > 
>> >> I have a shopping cart type system set up which keeps track of the cart
>> >> contents using a SESSION variable, where $_SESSION['cart'][$item_id'] is
>> >> equal to the quantity, so the name/value pair is all the information I 
>> >> need.
>> >> 
>> >> But sessions are unreliable on the free server I am currently using for 
>> >> this
>> >> website (not my choice), so I had start using cookies because users were
>> >> being sporadically logged out, sometimes just on a page refresh.
>> >> 
>> >> I want to find a way to set a cookie to remember the cart items as well, 
>> >> and
>> >> I thought setting a cookie for each item/quantity pair was the way to go
>> >> until I started trying to figure out how to unset all those cookies if the
>> >> user empties their cart.
>> >> 
>> >> Is there any way to set cookies with an array for the name? Intead of
>> >> $_COOKIE['item_number'] have $_COOKIE['cart']['item_number'] like I have 
>> >> the
>> >> SESSION?
>> > 
>> > 
>> > What about storing a unique ID in the cookie, and matching it up with
>> > information for that user in a database. It's sort of simulating a
>> > sessions, but without the session handler getting involved, which looks
>> > slightly messed up from what you've said.
>> > 
>> > Thanks,
>> > Ash
>> > http://www.ashleysheridan.co.uk
>> 
>> Blast your speedier typing!! =P
>> 
>> ~Philip
>> 
> 
> By the power of Kenco!
> 
> Thanks,
> Ash
> http://www.ashleysheridan.co.uk
> 

I hope you don't kiss your mother with that mouth!!


--- End Message ---
--- Begin Message ---
On Mon, 2009-12-07 at 16:53 -0600, Philip Thompson wrote:

> On Dec 7, 2009, at 4:46 PM, Ashley Sheridan wrote:
> 
> > On Mon, 2009-12-07 at 16:48 -0600, Philip Thompson wrote:
> >> 
> >> On Dec 7, 2009, at 4:40 PM, Ashley Sheridan wrote:
> >> 
> >> > On Mon, 2009-12-07 at 14:39 -0800, Allen McCabe wrote:
> >> > 
> >> >> I have a shopping cart type system set up which keeps track of the cart
> >> >> contents using a SESSION variable, where $_SESSION['cart'][$item_id'] is
> >> >> equal to the quantity, so the name/value pair is all the information I 
> >> >> need.
> >> >> 
> >> >> But sessions are unreliable on the free server I am currently using for 
> >> >> this
> >> >> website (not my choice), so I had start using cookies because users were
> >> >> being sporadically logged out, sometimes just on a page refresh.
> >> >> 
> >> >> I want to find a way to set a cookie to remember the cart items as 
> >> >> well, and
> >> >> I thought setting a cookie for each item/quantity pair was the way to go
> >> >> until I started trying to figure out how to unset all those cookies if 
> >> >> the
> >> >> user empties their cart.
> >> >> 
> >> >> Is there any way to set cookies with an array for the name? Intead of
> >> >> $_COOKIE['item_number'] have $_COOKIE['cart']['item_number'] like I 
> >> >> have the
> >> >> SESSION?
> >> > 
> >> > 
> >> > What about storing a unique ID in the cookie, and matching it up with
> >> > information for that user in a database. It's sort of simulating a
> >> > sessions, but without the session handler getting involved, which looks
> >> > slightly messed up from what you've said.
> >> > 
> >> > Thanks,
> >> > Ash
> >> > http://www.ashleysheridan.co.uk
> >> 
> >> Blast your speedier typing!! =P
> >> 
> >> ~Philip
> >> 
> > 
> > By the power of Kenco!
> > 
> > Thanks,
> > Ash
> > http://www.ashleysheridan.co.uk
> > 
> 
> I hope you don't kiss your mother with that mouth!!
> 


Not a coffee man? :p

Thanks,
Ash
http://www.ashleysheridan.co.uk



--- End Message ---
--- Begin Message ---
On Mon, Dec 07, 2009 at 02:39:28PM -0800, Allen McCabe wrote:

> I have a shopping cart type system set up which keeps track of the cart
> contents using a SESSION variable, where $_SESSION['cart'][$item_id'] is
> equal to the quantity, so the name/value pair is all the information I need.
> 
> But sessions are unreliable on the free server I am currently using for this
> website (not my choice), so I had start using cookies because users were
> being sporadically logged out, sometimes just on a page refresh.
> 
> I want to find a way to set a cookie to remember the cart items as well, and
> I thought setting a cookie for each item/quantity pair was the way to go
> until I started trying to figure out how to unset all those cookies if the
> user empties their cart.
> 
> Is there any way to set cookies with an array for the name? Intead of
> $_COOKIE['item_number'] have $_COOKIE['cart']['item_number'] like I have the
> SESSION?

First, don't use multiple cookies; already covered elsewhere. Second,
you can serialize/unserialize array data and store it compactly in a
cookie. See the serialize() and unserialize() functions on php.net.

Paul

-- 
Paul M. Foster

--- End Message ---
--- Begin Message ---
Hey all,

I have an HTML field like this

<input type="text" name="qty[]" value="!!quantity!!" size="4" style="text-align: right;" onblur="calculateBidUnit();">

... and what I need to do is pass to the calculateBidUnit function the value of quantity, do a calculation on it and plug into this field.

<input type="text" name="bid_unit_value[]" value="" size="4">

Which of course I know how to do for non-array values, but not sure how to get the values to do the calculation on the JS side if the fields are in an array.

Any help, as always, is greatly appreciated,
Skip

--
====================================
Skip Evans
PenguinSites.com, LLC
503 S Baldwin St, #1
Madison WI 53703
608.250.2720
http://penguinsites.com
------------------------------------
Those of you who believe in
telekinesis, raise my hand.
 -- Kurt Vonnegut

--- End Message ---
--- Begin Message ---
On Dec 7, 2009, at 5:02 PM, Skip Evans wrote:

> Hey all,
> 
> I have an HTML field like this
> 
> <input type="text" name="qty[]" value="!!quantity!!" size="4" 
> style="text-align: right;" onblur="calculateBidUnit();">
> 
> ... and what I need to do is pass to the calculateBidUnit function the value 
> of quantity, do a calculation on it and plug into this field.
> 
> <input type="text" name="bid_unit_value[]" value="" size="4">
> 
> Which of course I know how to do for non-array values, but not sure how to 
> get the values to do the calculation on the JS side if the fields are in an 
> array.
> 
> Any help, as always, is greatly appreciated,
> Skip

This question is probably more appropriate for a JS list... but I'm not mean, 
so I'll let you know. The easiest way would be to update the blur event qty 
input:

onblur="calculateBidUnit(this.value);"

Now you have the value sent to that function. Another way would be to give your 
input and output an id each - let's say 'qty' and 'bid_unit_value', 
respectively. Then reference those ids in your function. This gives you the 
following:

<input type="text" name="qty[]" value="!!quantity!!" 
onblur="calculateBidUnit();" id="qty" />
<input type="text" name="bid_unit_value[]" value="" id="bid_unit_value" />

<script type="text/javascript">
function calculateBidUnit () {
    var qty = document.getElementById('qty');
    var buv = document.getElementById('bid_unit_value');
    buv.value = qty.value;
}
</script>

I'll give you a small warning. All browsers are not alike, so my recommendation 
would be to use a library that handles the cross-browser compatibility portion 
of javascript (I use Mootools). Nonetheless, the above *should* work. Learning 
the bare bones of javascript will help with the more complicated stuff and 
you'll be smarter for it! =P

Hope that helps,
~Philip

--- End Message ---
--- Begin Message ---
Hey Philip,

But will that ID value identify the right member of each array? I thought about that but just assumed that it would not.

Skip

Philip Thompson wrote:
On Dec 7, 2009, at 5:02 PM, Skip Evans wrote:

Hey all,

I have an HTML field like this

<input type="text" name="qty[]" value="!!quantity!!" size="4" style="text-align: right;" 
onblur="calculateBidUnit();">

... and what I need to do is pass to the calculateBidUnit function the value of 
quantity, do a calculation on it and plug into this field.

<input type="text" name="bid_unit_value[]" value="" size="4">

Which of course I know how to do for non-array values, but not sure how to get 
the values to do the calculation on the JS side if the fields are in an array.

Any help, as always, is greatly appreciated,
Skip

This question is probably more appropriate for a JS list... but I'm not mean, 
so I'll let you know. The easiest way would be to update the blur event qty 
input:

onblur="calculateBidUnit(this.value);"

Now you have the value sent to that function. Another way would be to give your 
input and output an id each - let's say 'qty' and 'bid_unit_value', 
respectively. Then reference those ids in your function. This gives you the 
following:

<input type="text" name="qty[]" value="!!quantity!!" onblur="calculateBidUnit();" 
id="qty" />
<input type="text" name="bid_unit_value[]" value="" id="bid_unit_value" />

<script type="text/javascript">
function calculateBidUnit () {
    var qty = document.getElementById('qty');
    var buv = document.getElementById('bid_unit_value');
    buv.value = qty.value;
}
</script>

I'll give you a small warning. All browsers are not alike, so my recommendation 
would be to use a library that handles the cross-browser compatibility portion 
of javascript (I use Mootools). Nonetheless, the above *should* work. Learning 
the bare bones of javascript will help with the more complicated stuff and 
you'll be smarter for it! =P

Hope that helps,
~Philip

--
====================================
Skip Evans
PenguinSites.com, LLC
503 S Baldwin St, #1
Madison WI 53703
608.250.2720
http://penguinsites.com
------------------------------------
Those of you who believe in
telekinesis, raise my hand.
 -- Kurt Vonnegut

--- End Message ---
--- Begin Message ---
On Dec 7, 2009, at 6:32 PM, Skip Evans wrote:

> Hey Philip,
> 
> But will that ID value identify the right member of each array? I thought 
> about that but just assumed that it would not.
> 
> Skip
> 
> Philip Thompson wrote:
>> On Dec 7, 2009, at 5:02 PM, Skip Evans wrote:
>>> Hey all,
>>> 
>>> I have an HTML field like this
>>> 
>>> <input type="text" name="qty[]" value="!!quantity!!" size="4" 
>>> style="text-align: right;" onblur="calculateBidUnit();">
>>> 
>>> ... and what I need to do is pass to the calculateBidUnit function the 
>>> value of quantity, do a calculation on it and plug into this field.
>>> 
>>> <input type="text" name="bid_unit_value[]" value="" size="4">
>>> 
>>> Which of course I know how to do for non-array values, but not sure how to 
>>> get the values to do the calculation on the JS side if the fields are in an 
>>> array.
>>> 
>>> Any help, as always, is greatly appreciated,
>>> Skip
>> This question is probably more appropriate for a JS list... but I'm not 
>> mean, so I'll let you know. The easiest way would be to update the blur 
>> event qty input:
>> onblur="calculateBidUnit(this.value);"
>> Now you have the value sent to that function. Another way would be to give 
>> your input and output an id each - let's say 'qty' and 'bid_unit_value', 
>> respectively. Then reference those ids in your function. This gives you the 
>> following:
>> <input type="text" name="qty[]" value="!!quantity!!" 
>> onblur="calculateBidUnit();" id="qty" />
>> <input type="text" name="bid_unit_value[]" value="" id="bid_unit_value" />
>> <script type="text/javascript">
>> function calculateBidUnit () {
>>    var qty = document.getElementById('qty');
>>    var buv = document.getElementById('bid_unit_value');
>>    buv.value = qty.value;
>> }
>> </script>
>> I'll give you a small warning. All browsers are not alike, so my 
>> recommendation would be to use a library that handles the cross-browser 
>> compatibility portion of javascript (I use Mootools). Nonetheless, the above 
>> *should* work. Learning the bare bones of javascript will help with the more 
>> complicated stuff and you'll be smarter for it! =P
>> Hope that helps,
>> ~Philip

Each text input will only contain 1 value... and contain 1 unique "id." So, if 
you have multiple input boxes with the same name (qty[]), only the $_POST 
output will contain an array of each value. See below...

<input type="text" name="qty[]" value="1" id="qty1" onblur="calc(this.value);" 
/>
<input type="text" name="qty[]" value="2" id="qty2" onblur="calc(this.value);" 
/>
<input type="text" name="qty[]" value="3" id="qty3" onblur="calc(this.value);" 
/>

<input type="text" name="bid_unit_value[]" value="" id="buv" />

<script type="text/javascript">
function calc (value) {
    document.getElementById('buv').value = value;
}
</script>

When you blur qty1, buv will receive the value 1; blur qty2, buv will be 2; and 
so on. The last input box that you blur on will determine buv's final value 
(unless you throw in some logic to handle this)...

<script type="text/javascript">
function calc (value) {
    var buv = document.getElementById('buv');
    if (buv.value == '') buv.value = value;
}
</script>

So, let's say you blur on qty2 and then submit the form, your PHP script will 
have this in $_POST...

Array
(
    [qty] => Array
        (
            [0] => 1
            [1] => 2
            [3] => 3
        )
    [bid_unit_value] => Array
        (
            [0] => 2
        )
)

If this is not what you're wanting, you will need to modify the behavior above. 
If you're wanting the bid_unit_value to contain all the values of each blur, 
you may want to do something like this...

<script type="text/javascript">
function calc (value) {
    var buv = document.getElementById('buv');
    if (buv.value == '') buv.value = value;
    else buv.value += '|'+value;
}
</script>

Which may result from each blur in $_POST to be...

Array
(
    [qty] => Array
        (
            [0] => 1
            [1] => 2
            [3] => 3
        )
    [bid_unit_value] => Array
        (
            [0] => 2|1|3
        )
)

Or something along those lines. Then you can just explode() on that first index 
to get individual values. Maybe you can clarify your ultimate goal and we can 
assist you in what the best plan is.

Hope that helps,
~Philip

--- End Message ---
--- Begin Message ---


I'm using PHP 5.2.11 with Apache 2 (and i also tried Apache 2.2)

However, when I add this entry to my httpd.conf:
<code>
LoadModule php4_module "C:/Program Files/php/sapi/php4apache.dll"
</code>
Apache will crash when trying to start the service.
If I comment the line out, Apache starts just fine.

Thanks for your help.
Regards, 

                                          
_________________________________________________________________
Windows Live Hotmail: Your friends can get your Facebook updates, right from 
Hotmail®.
http://www.microsoft.com/middleeast/windows/windowslive/see-it-in-action/social-network-basics.aspx?ocid=PID23461::T:WLMTAGL:ON:WL:en-xm:SI_SB_4:092009

--- End Message ---

Reply via email to