RE: [PHP] Passing HTML array index to JS?

From: Date: Tue, 08 Dec 2009 12:33:49 +0000
Subject: RE: [PHP] Passing HTML array index to JS?
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-300310@lists.php.net to get a copy of this message
On Tue, 2009-12-08 at 12:34 +0000, Ford, Mike wrote: > > > -----Original Message----- > > From: Skip Evans [mailto:skip@bigskypenguin.com] > > Sent: 07 December 2009 23:03 > > To: php-general@lists.php.net > > Subject: [PHP] 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@leedsmet.ac.uk > 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

« previous php.general (#300310) next »