I’m currently making an online shop using php. I don’t know any javascript but I’m not bad with php so I can analyze a script and probably work out what it does (javascript). Here’s what I want to do. When a user selects a different weight, I want it to update the displayed price. However, there will be multiple products on a page so the script has to work for many products and not just one. I suggest you copy the below table into something like dreamweaver.
[code=html]
<table width=”100%” border=”0″ cellspacing=”0″ cellpadding=”3″>
<tr>
<td width=”23%” valign=”middle”>Weight:</td>
<td width=”39%” align=”left” valign=”middle”>
<form method=”post” action=””>
<select id=”weight1″ name=”weight” style=”width:108px;”>
<option value=”1kg”>1kg ($15.00)</option>
<option value=”500g”>500g ($10.00)</option>
<option value=”250g”>250g ($7.00)</option>
</select>
</form>
</td>
<td id=’price1′ width=”38%”>$15.00</td>
</tr>
</table>
<br />
<br />
<table width=”100%” border=”0″ cellspacing=”0″ cellpadding=”3″>
<tr>
<td width=”23%” valign=”middle”>Weight:</td>
<td width=”39%” align=”left” valign=”middle”>
<form method=”post” action=””>
<select id=”weight2″ name=”weight” style=”width:108px;”>
<option value=”1kg”>1kg ($15.00)</option>
<option value=”500g”>500g ($10.00)</option>
<option value=”250g”>250g ($7.00)</option>
</select>
</form>
</td>
<td id=’price2′ width=”38%”>$15.00</td>
</tr>
</table>
How hard would it be to change the displayed price when the user selects a different weight? It will be cosmetic only. I understand that javascript uses element ID’s for things like this. You’ll notice in the above tables that I’ve set the weight and price id’s differently between the price id’s and the weight id’s. If someone could write me a little script to do this for the above html, then that would be really awesome and much appreciated.
Cheers!