tags:

views:

24

answers:

1

I have a select box whose onChange attribute executes the functions given as:

<select id="shipping_method" name="shipping_method" onChange="javascript:quantity(), price(), Shipping();" style="width: 209px;">
    <option value="">Select Shipping</option>
    <option value="standard">Standard (7 - 12 days from proof)</option>
    <option value="expedited">Expedited (5 work days from Proof)</option>
</select>
​
+3  A: 

In JavaScript, a comma separates a sequence of expressions. The expressions are evaluated in turn from left to right. This is often used when declaring variables:

var var1, var2 = 12, var3 = true;

And omitting braces from if statements:

if (something == true)
    doSomething(),
    doAnotherThing();
else
    doSomethingElse();

But they can generally be used to separate any expression, providing the expressions that are being seperated don't contain language construct statements like return, if, break, etc.

In the example you supplied, it's more or less the same as

onchange="quantity(); price(); Shipping();"

(note the javascript: label is not required in event handlers and it doesn't do what you probably think it does. Also, to avoid confusion when working with DOM events, try and stick to lowercase event names instead of camelCase.

Andy E
+1 Thanks Mate for the rocket science info(for me)...
OM The Eternity