• Notice regarding image hosts and attachments. See here.

HTML/PHP/Javascript problem.

Soldato
Joined
18 Oct 2002
Posts
2,996
I've been scratching my head on this one, but my Javascript skills are rubbish, so I'm struggling on working out how to do this......
I've got a HTML form. A basic version is as follows:
Code:
<form>
 <select name=select1>
  <option selected>Please Choose</option>
  <option value=option1>Option 1 £100.00</option>
  <option value=option2>Option 2 £200.00</option>
  <option value=option3>Option 3 £300.00</option>
 </select>
 <select name=select2>
  <option selected>Please Choose</option>
  <option value=option1>Option 1 £100.00</option>
  <option value=option2>Option 2 £200.00</option>
  <option value=option3>Option 3 £300.00</option>
 </select>
</form>
Note, the actual form select options are populated using PHP code pulling data from a database. The data pulled is the "value=xxxxxx" and the actual "Option x £xxx.xx".

Basically, what I want to do is total up the sum of the options selected.
Example:
If someone selects Option 1 for select1, and Option 3 for select2, the total would show £400.00


I want the display to update dynamically, before the form is submitted, so I was thinking JavaScript is the answer.

I've trawled lots of websites and tried a couple of things, but I really am utterly stuck on how to do this, although I'm sure it's perfectly possible.

Someone help me!! :)
 
That's superb! :)
Is there a way though to pull the number (eg.300) from the text in between the <option> </option tags?
I'm currently using value= to pass an item code over.
eg
Code:
<option value=000142 name=item1>Item 1, worth £152.44p</item>
<option value=000143 name=item2>Item 2, worth £474.83p</item>

Sorry to be fussy....I feel very ungrateful! :) Appreciate your help a lot
 
jdickerson - thanks mate. What I was meaning was to grab the value using Javascript, and use it for the total sum.

Geforce - okay, I've made that change so that "value" now looks like:
Code:
<option value=001_3.5>Item 001 worth £3.5m</option>
<option value=002_8.2>Item 002 worth £8.2m</option>
I'll need to alter the PHP that then processes those values to remove the _3.5 bit, but I can do that.

So, is it possible using the JavaScript to grab the _3.5 part, and use that number for doing the sums?
 
Back
Top Bottom