• 0

[HTML] Currency Conversion....


Question

I am helping out a friend with a project and he is trying to figure out how to make the result round to the nearest tenths place. Below is the code please help if you can. Thanks in advance!!!! :)

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Currency Conversion Final Project</title>
<script>
function calc()
{
var amt = document.f1.t1.value;
var rate = document.f1.s1.value;
temp = amt / rate;
//dollars = 1/temp;
alert ("Dollars : " + temp)
}
</script>
</head>

<body>
<form id="form1" name="f1" method="post" action="">
<strong> Currency Conversion Application</strong>
<table width="558" border="0" cellspacing="0" cellpadding="0">
<tr>
	<td width="167">Enter amount (foreign currency) </td>
	<td width="252"><label>
	  <input name="t1" type="text" size="10" maxlength="10" />
	</label></td>
  </tr>
  <tr>
	<td>Select Currency </td>
	<td>
	  <label>
		<select name="s1">
		  <option value="1.4680">Canadian dollars</option>
		  <option value="9.5085">Mexican pesos</option>
		  <option value="0.6313">English pounds</option>
		  <option value="104.9200">Japanese yen</option>
		  <option value="6.2561">French francs</option>
		</select>
		</label>
	</td>
  </tr>
  <tr>
  <td> </td>
  <td><label>
	<input type="submit" name="Submit" value="Submit" onClick="calc()"/>
  </label></td>
  </tr>
</table>
</form>
</body>
</html>

Link to comment
Share on other sites

11 answers to this question

Recommended Posts

  • 0

Round({origional value here}, 1)

But, aren't you wanting cents as well, like $5.25 instead of $5.2?? If so, Round({origional value here}, 2) should work

Link to comment
Share on other sites

  • 0

Thanks, where exactly would I put that in the code? And yes I did mean cents like .25 :p

Link to comment
Share on other sites

  • 0

Thanks, but it is still not working. Here is the code now...

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Currency Conversion Final Project</title>
<script>
function calc()
{
var amt = document.f1.t1.value;
var rate = document.f1.s1.value;
temp = amt / rate,2;
//dollars = Round(temp = amt / rate,2)
alert ("Dollars : " + temp)
}
</script>
</head>

<body>
<form id="form1" name="f1" method="post" action="">
<strong> Currency Conversion Application</strong>
<table width="558" border="0" cellspacing="0" cellpadding="0">
<tr>
	<td width="167">Enter amount (foreign currency) </td>
	<td width="252"><label>
	  <input name="t1" type="text" size="10" maxlength="10" />
	</label></td>
  </tr>
  <tr>
	<td>Select Currency </td>
	<td>
	  <label>
		<select name="s1">
		  <option value="1.4680">Canadian dollars</option>
		  <option value="9.5085">Mexican pesos</option>
		  <option value="0.6313">English pounds</option>
		  <option value="104.9200">Japanese yen</option>
		  <option value="6.2561">French francs</option>
		</select>
		</label>
	</td>
  </tr>
  <tr>
  <td> </td>
  <td><label>
	<input type="submit" name="Submit" value="Submit" onClick="calc()"/>
  </label></td>
  </tr>
</table>
</form>
</body>
</html>

You guys are welcome to take the code and see if you can get it to work. Thanks.

Link to comment
Share on other sites

  • 0
var amt = whatever;
var rate = whatever;

// Amount x Rate for conversion
var newAmt = round(amt * rate, 2);

alert(newAmt);

// Stop page redirecting
return false;

Link to comment
Share on other sites

  • 0

Guys I greatly appreciate all your help but for some reason or another it just does not work. With the latest code provided above I no longer get a pop-up with the result. I am sure I am over looking something super simple. Thanks again for all your help and hopefully we can get this working :)

Link to comment
Share on other sites

  • 0

Try this.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "<A href="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd</A>">
<html xmlns="<A href="http://www.w3.org/1999/xhtml">http://www.w3.org/1999/xhtml</A>">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Currency Conversion Final Project</title>
<script>
function calc()
{
 var amt = document.getElementById('t1').value;
 var rate = document.getElementById('s1').value;
 var newAmt = amt * rate;</P> <P> alert(newAmt.toFixed(2));
}
</script>
</head></P> <P><body>
<strong> Currency Conversion Application</strong>
<table width="558" border="0" cellspacing="0" cellpadding="0">
<tr>
	<td width="167">Enter amount (foreign currency) </td>
	<td width="252"><label>
	  <input name="t1" id="t1" type="text" size="10" maxlength="10" />
	</label></td>
  </tr>
  <tr>
	<td>Select Currency </td>
	<td>
	  <label>
		<select name="s1" id="s1">
		  <option value="1.4680">Canadian dollars</option>
		  <option value="9.5085">Mexican pesos</option>
		  <option value="0.6313">English pounds</option>
		  <option value="104.9200">Japanese yen</option>
		  <option value="6.2561">French francs</option>
		</select>
		</label>
	</td>
  </tr>
  <tr>
  <td> </td>
  <td><label>
	<button type="button" name="btn_calc" id="btn_calc" onclick="calc()"/>Submit</button>
  </label></td>
  </tr>
</table>
</body>
</html>

Link to comment
Share on other sites

  • 0

Make sure you clean up Drakja's code a little before using. It has some bad HTML in there (anchors in the first two lines, paragraphs in the last JS line).

Link to comment
Share on other sites

  • 0

Thanks a million Drakja I did some code clean up and it works like a charm! You are a life saver! :)

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.