Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Simple value changing in forms HELP!!!

Status
Not open for further replies.

FluffyBiker

Programmer
Nov 12, 2007
3
GB
Hey all, I'm a bit new to JavaScript so bear with me!

My main Website uses the Paypal buy it now buttons which i have found i can manipulate by using drop down menus.

What i Want to do now is capture 2 values from each option (one to alter the despcription one to alter the price) but i'm failing to succeed.

This is what I have (edited out the non relevant bits)

the code bit

function hondachainselect()
{
document.hondachain.item_name.value = document.hondachain.hondachainproduct.value + document.hondachain.hondachain_bike.value

}

the html form bit

<form target="paypal" action=" method="post" name="hondachain">

<b> Please Choose your colour:<br></b>
<select name="hondachain_bike" onChange="hondachainselect()">
<option value=" 0 ">Choose Bike</option>
<option value="CRF50 04-06" >CRF50 04-06 £19.99</option>
<option value="CRF70 04-06" >CRF70 04-06 £19.99</option>
<option value="CRF100 04-06" >CRF100 04-06 £29.99</option>

</select>

<br><font size="4"><b>from £19.99</b><br></font>
<input type="hidden" name="hondachainproduct" value="Chain & Sprocket Kit - ">

<input type="image" src=" border="0" name="submit" alt="Make payments with PayPal - it's fast, free and secure!">

<input type="hidden" name="item_name">
<input type="hidden" name="amount">

</form>

with that the "item_name" comes out correctly but I've given up how to get a 2nd value from the options to assign to "amount"

Many thanks in advance for your help!!
 
You can get the text property of the option selected and parse the amount from there. Or you could create a JS array with the amount in that.

Code:
var bike = new Array(), bi=0;
bike[bi++] = {model:'CRF50 04-06', price:'£19.99'};
bike[bi++] = {model:'CRF70 04-06', price:'£19.99'};
bike[bi++] = {model:'CRF100 04-06', price:'£29.99'};

function hondachainselect()
{
var bikevalue = document.hondachain.hondachain_bike.value;
document.hondachain.item_name.value = document.hondachain.hondachainproduct.value + bikevalue;

for (var bi=0;bi<bike.length;bi++)
  {
  if (bike[B][I].model == bikevalue)
    {
    document.hondachain.amount.value = bike[B][I].price;
    break;
    }
  }

}

Lee
 
Ok Arrays is not something I've played with yet...

Not seeing how to make that work (sorry and THANK YOU!)
 
YIPPEEE bit of a fiddle and it all works WOOHOO!!!!!!

THANK YOU SOOOO MUCH!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top