/    Sign up×
Community /Pin to ProfileBookmark

Update Price on Selection

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>
[/code]

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!

to post a comment
JavaScript

0Be the first to comment 😎

×

Success!

Help @Wardrop spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.16,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...