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 Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Multiplying variable by 100

Status
Not open for further replies.

Jon12345

Programmer
Jul 26, 2002
4
GB
I have a form called order.htm. A field called $amount is filled in with the order value, say $97.

However, When someone hits the "Click to Order" button, I need to multiply that value by 100.

This now larger value is sent to my merchant accounts secure server.

How can I do this?

I can do this easy enough without any scripts to just send $97, but the customer will have to enter 9700 instead of 97. I don't want that - it might confuse them!

Thanks,

Jon
 
you can use javascript to submit the form once you have modifed the value. In the form tag add

onsubmit="myFunction()"

and in a script block or external js file add myFunction somehting like this

function myFunction(){
document.formname.elementname.value *= 100;
document.formname.submit();
}

and that will multiply the value in the text fiedl by 100 before submitting

hope this helps

Rob
 
Thanks for your exceedingly quick reply!

I am confused what I substitute for formname etc.

The order page is called orders.htm, the amount field is is called "amount", and after submission it goes to page merchant.html.

Can you clarify me what I substitute?

Also, do you know the rough percentage of surfers who can process javascript?

Thanks,

Jon
 
Jon,

Firs let me say I admire your ways to increase your revenue (if(customerNotSee){$$*100}).

What Rob tried to explane is that your $ field is in a form like so:
<form id=formname>
<input type=text id=elementname>

What you could do is set a hidden value for your $ value and use that value after it is submitted. The person filling out the form does not know that the $ is *100 because he/she cannot see this field.
Here is an example but this example states that the $ has to change (from empty to something or something to something else) before the hidden $ field wil be filled in.


<input type=hidden id=hidPrice>
<input type=text id=txtPrice onchange=&quot;document.getElementById('hidPrice').value = this.value*100;&quot;>
 
if I read the initial question right this is all you watn to do right?

<html>
<body>
<form name=&quot;form1&quot;>
<input type=&quot;text&quot; id=&quot;txtPrice&quot; value=&quot;97&quot; onChange=&quot;form1.txtPrice.value = this.value*100;&quot;>
</form>
</body>
</html> I help at your own risk, if I brake it sorry! But if I fixed it, let me know.[thumbsup2]
admin@onpntwebdesigns.com
 
here's a example. not showing the value of the field (price) I wouldn't use the onChange event due to if they do not change the field. onBlur even at that they will have to tab through the bow to perform the calc.

<html>
<body>
<form name=&quot;form1&quot; method=&quot;get&quot; action=&quot;new.htm&quot;>
<input type=&quot;hidden&quot; name=&quot;txtCalc&quot; id=&quot;txtCalc&quot; value=&quot;&quot;>
<input type=&quot;text&quot; id=&quot;txtPrice&quot; value=&quot;97&quot; onBlur=&quot;document.form1.txtCalc.value = document.form1.txtPrice.value*100;&quot;>
<input type=&quot;button&quot; value=&quot;submit&quot; onClick=&quot;javascript:window.alert(form1.txtCalc.value);&quot;>
</form>
</body>
</html> I help at your own risk, if I brake it sorry! But if I fixed it, let me know.[thumbsup2]
admin@onpntwebdesigns.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top