Forum Moderators: open
I have what is I think a straightforward problem, but I'm pretty dyslexic with programming, and as such find it near impossible to create individual code from general examples. I have tried to code from scratch, but it's so flawed, I'm at a loss.
My current procedure is this:
I have a site where the customer fills out a form (there is an array which assigns a price according to choice of item and country).
on completing the form, it is written to a database, the basics of the order is displayed, and then the options to go onto payment.
basic display is
<b>Order No </b> <<ID>><br>
<b>Item </b> <<description>><br>
<b>Price </b>£<<price>><br>
This all works without any problems.
On the same page, I want to have a separate payment option, which would be identical, except the currency would be in dollars.
So what I want to do is take the variable 'price' and create another (say, 'price2') which is would be the price in USD.
I would like it to be something like (i know this isnt proper code)
price2=price*x
and I could just go into the html of my page and alter 'x' every week (or day, with the current volatility)
If possible, I really don't want to alter the database structure, especially as this is a trial period.
I apologise for such a lengthy message for a straightforward problem, but I guess the more information the better.
Any advice greatly appreciated.
NB - the quotation box has put extra line break.
just put:
var coef=1.5
function pricing(){
TabPrices=document.getElementsByName('Price')
for (i=0;i<TabPrices.length;i++){
TabPrices[i].value*=coef;
}
}
in a text file and call it increase.js
then in your html page head:
<script type='text/javascript' src="increase.js"></script>
in your page:
<body onload="pricing()">
item1 <input type="text" readonly name="Price" value=2 /><br/>
item2<input type="text" readonly name="Price" value=4 /><br/>
item3<input type="text" readonly name="Price" value=8 /><br/>
</html>
do not forget to put noscript tags in your page as if js is not activated prices would remain as value in input ...
you then only need to change coef in je file and all your pages will be updated in price ...
<script type='text/javascript'>
var coef=1.57
function pricing(){
TabPrices=document.getElementsByName('Price')
for (i=0;i<TabPrices.length;i++){
document.getElementsByName(TabPrices[i].name+'GBP')[i].value=TabPrices[i].value*coef;
}
}
</script>
</head>
<body onload="pricing()">
item1 USD<input type="text" readonly name="Price" value=2 />GBP<input type="text" readonly name="PriceGBP" value=2 /><br/>
item2 USD<input type="text" readonly name="Price" value=4 />GBP<input type="text" readonly name="PriceGBP" value=2 /><br/>
item3 USD<input type="text" readonly name="Price" value=8 />GBP<input type="text" readonly name="PriceGBP" value=2 /><br/>
<br/>
</body>
</html>
In head
<script type='text/javascript'>
var coef=1.57
function pricing(){
TabPrices=document.getElementsByName('Price')
for (i=0;i<TabPrices.length;i++){
document.getElementsByName(TabPrices[i].name+'GBP')[i].value=TabPrices[i].value*coef;
}
}
</script>
in body
<body onload="pricing()">
My original form value was defined as 'price' so I have used in body the following code
<<input type="hidden" name="Price" value="<<price>>" />
<input type="readonly" name="PriceGBP" /><br/>
so the usual price carried over would be 25.00, so this is displaying in the box 39.25.
So far, so good.
So now I want to use this new calculation for two things.
for my existing information, i recap the order as such
<b>Order No </b> <<ID>><br>
<b>Item </b> <<description>><br>
<b>Price<br> <<price>><br>
and in when sending my form to payment processor, i use the following.
<form action https://www.zzzzzz.com/yyyy" method="post">
...
<input type="hidden" name="amount" value="<<price>>">
...
</form>
These currently work fine. So I want essentially duplicates of these for the new price.
But I've currently been unable to carry it over - If I replace Price with PriceGBP or other variations, all is blank.
Thanks for the help so far.
I suppose its an issue of forwarding - if I'm trying to use the recap
<b>Order No </b> <<ID>><br>
<b>Item </b> <<description>><br>
<b>Price<br> <<price>><br>
and the form elements
<form action https://www.zzzzzz.com/yyyy" method="post">
...
<input type="hidden" name="amount" value="<<price>>">
...
</form>
I am unable to get the new variable to appear in something like this (using, for example,
<<PriceGBP>>)
the <<>> is what I used to get to display the fields - It probably has nothing to do with Javascript, but it works on the existing details - whether I have to permanently define the PriceGBP I don't know. I would just like to be able to show it in that manner and also have it passed in a form.
thanks for your help in getting the formula and the calcuations set up, was greatly appreciated.
James