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

Simple conversion formatter + Form maybe? I'm clueless really.

Status
Not open for further replies.

jakweeze

IS-IT--Management
Nov 17, 2010
6
US
PREFACE:
A friend of mine and myself (being super amateur at web design) have been trying to build a site in order to see a particular good (money in a game... not sure why I feel nerdy about that when posting in a JScript forum...)

So I have ripped and retailored code from other sites and I'm not really a big fan of just grabbing someone's code, but I've yet to grasp what I'm trying to do and/or not sure of the correct terminology to research it to learn it fully.

PROBLEM:
I would like to make a simple converter box where person puts in number in boxA, boxB then returns (without clicking or changing type focus) 20% of boxA

document.convert.value = document.convert.InUnit.value * 0.20

Kind of like so, and then I would like to be able to have a checkout button below that that sends the value of boxB to paypal (which I'm not sure if THIS section is doable without PHP on the server side.

The website I'm working on is listed below, I have an example of what I'd LIKE it to look like on the page, but the code there you can see is awefully diluted, and I'm sure there's a way to streamline it back down to just a few if / var statements

Thank you much for your time/code knowledge/or finger pointing directions!

 
I would like to make a simple converter box where person puts in number in boxA, boxB then returns (without clicking or changing type focus) 20% of boxA

document.convert.value = document.convert.InUnit.value * 0.20

You could use onkeyup event so that it calculates every time something is typed into the box, though I suggest checking for a valid number before attempting any calculations. Assuming the name of the form the textboxes are in is Convert, and the names of the texboxes are boxA and boxB:
Code:
function calc_Twenty(tbox){
  if(isNaN(tbox.value)!=true){
    document.convert.boxB.value=parseInt(tbox.value) * 0.20;
    return true;
  }
  else{ return false;}
  }
</script>
<form name="convert">
<input type="text" onkeyup="calc_Twenty(this);"><input type="text" name="boxB">
</form>

As far as paypal goes, any hidden inputs that exists in the form that contains the paypal button should get sent to Paypal. You would need to have st up your pay pal account to accept those input variables. I'm not very knowledgeable about paypal so maybe someone else can chime in here, or looking in Paypals own forums may yield more help.

----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Behind the Web, Tips and Tricks for Web Development.
 
Code:
<script type="text/javascript" language="JavaScript">
function calc_Twenty(tbox){
  if(isNaN(tbox.value)!=true){
    document.convert.boxB.value=parseInt(tbox.value) * 0.20;
    return true;
  }
  else{ return false;}
  }
</script>
<form name="convert">
    <h2><span id="Title">Please read the following:</span></h2>
	<p><span class="Text"><span class="Important">All plat is currently $0.20 per Platinum.<br />
	  Contact us prior to checkout  via the site, <u>not in game.</u></span></span><br />
  	<p> Cost calculator:<br /><span class="Important">
<input type="text" style="text-align: right" size=1 maxlength=4 value="" onkeyup="calc_Twenty(this);">Platinum for: <input type="text" style="text-align: right; background-color: transparent; border:hidden; font-weight:bold;" size=5 maxlength=5 value="0.00" name="boxB">USD <strong>-Please Update Quantity at Checkout!-</strong>
</form>

This is what I have made up so far outta your example to me (which, thanks a lot btw) Now my next question is I have found the code of:
Code:
toFixed(x)
but I've yet to be successful at figuring out how to roll that into the prior equation so that the results basically is showing two decimal places and only two, at all times.

Thanks again for all your support!
 
Woo Got it!
it was the use of () that was tripping me up, I ended up with:
Code:
<script type="text/javascript" language="JavaScript">
function calc_Twenty(tbox){
  if(isNaN(tbox.value)!=true){
    document.convert.boxB.value="$" + (parseInt(tbox.value) * 0.20).toFixed(2);
    return true;
  }
  else{ return false;}
  }
</script>
I had tried it several ways by just attaching the .toFixed(2) someplace to no avail till I saw an example of it with () around the leading arguments excellentttt :D thanks again!

Now to just try and figure out how to submit the value of -tbox- to PayPal and my page will be golden =)
 
Glad you sorted it out.

----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Behind the Web, Tips and Tricks for Web Development.
 
@Phil
off topic Phil but if you'd like to see what I'm actually fully working on head over to
any tips or suggestions I'd love to hear about em!

(also really trying to figure out what's better for incorporation into the main site:
)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top