RE: Passing HTML array index to JS?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, 2009-12-08 at 12:34 +0000, Ford, Mike wrote:

> 
> > -----Original Message-----
> > From: Skip Evans [mailto:skip@xxxxxxxxxxxxxxxxx]
> > Sent: 07 December 2009 23:03
> > To: php-general@xxxxxxxxxxxxx
> > Subject:  Passing HTML array index to JS?
> > 
> > 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.
> 
> H'mm, in my experience the only surefire foolproof way to make sure you pick the correct "bid_unit_value[]" input to match the corresponding "qty[]" is to actually supply specific array indexes (so "qty[1]", "bid_unit_value[1]"; "qty[2]", "bid_unit_value[2]"; etc.). There are other Javascript approaches that work in theory, but I've never been convinced of their robustness.
> 
> As to addressing these elements, I merely observe that in Javascript, by definition a.z is *identical* to a["z"]. Application of this to the current situation is left as an exercise for the reader.
> 
> Cheers!
> 
> Mike
>  -- 
> Mike Ford,
> Electronic Information Developer, Libraries and Learning Innovation,  
> Leeds Metropolitan University, C507, Civic Quarter Campus, 
> Woodhouse Lane, LEEDS,  LS1 3HE,  United Kingdom 
> Email: m.ford@xxxxxxxxxxxxxx 
> Tel: +44 113 812 4730
> 
> 
> 
> 
> 
> To view the terms under which this email is distributed, please go to http://disclaimer.leedsmet.ac.uk/email.htm
> 


What about using the DOM for getting to these elements and their
properties?

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



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux