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

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

Reply via email to