Link to home
Start Free TrialLog in
Avatar of majdolyan
majdolyanFlag for Saudi Arabia

asked on

multiply numbers within HTML

Hi,

I have a placeholder (e.g. ##total## which represent a number) and want to multiply it by a number in an HTML code. Can I do it in just HTML? or do I need to have a javascript?

Can you give me the sample of the code in HTML or javascript to be added to an HTML page.

Regards,
Avatar of stormist
stormist

No, you cannot do it in just HTML.

Here is an example of multiplying in javascript:
http://www.kirupa.com/forum/showthread.php?t=188261
You can count with HTML but not multiply.  To count use <ol> and <li>
    <ol>
       <li>item</li>
       <li>item</li>
       <li>item</li>
    </ol>

but to multiply you will need to use JavaScript.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Title</title>
</head>
<body>
 
<h1>Dynamic Math</h1>
 
<p>What does <span id="value1">12</span> multiplied by <span id="value2">64</span> equal?</p>
 
<p><strong>Answer: <span id="answer"></span></strong></p>
 
<address>Footer</address>
 
<script type="text/javascript">
 
var value1 = document.getElementById('value1').innerHTML;
var value2 = document.getElementById('value2').innerHTML;
var answer = document.getElementById('answer');
 
if (value1 && value2 && answer) answer.innerHTML = ( value1 * value2 )
 
</script> 
 
</body>
</html>

Open in new window

Avatar of majdolyan

ASKER

Thanks for the hints.

I tried to apply the example to my code, but I couldn't put the place holders in the javascript.
How can I write ##total## into the code?

My simple multiplication is the following

value = ##total## * 3.75;
document.write(value);

Thanks in advance
FYI

the placeholder ##total## is coming from the backend php file.

Thanks
Can you change your PHP to do this:
<span id="value1">12</span>

Instead of this:
##12##

?
No, it's encrypted!
Can you post all or at least some of the HTML that the PHP outputs so I can see what it looks like?
This is a snippet of the template.
The header and footer are stored in different html pages.

As I said earlier what I want to multiply ##total## by 3.75 and display the new value without removing original ##total##.
<!-- TITLE: Order Information -->
 
<blockquote>
<font color=red><b>
Order Number:&nbsp; ##id##<br />
Order Details:&nbsp; ##term_out##<br />
Amount: ##CURR_SIGN####total##
</b></font></p>
</blockquote>

Open in new window

That is a snippet of the template, but what does the HTML that the template outputs look like?
ASKER CERTIFIED SOLUTION
Avatar of hankknight
hankknight
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I opened the page in the browser and took for you the source of the page.
I hope it's what you are looking for.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
 
<html>
<head>
 
<title> Order Information</title>
 
<link rel="stylesheet" href="img/main.css" type="text/css">
 
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
 
 
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="expires" content="0">
 
<meta http-equiv="cache-control" content="no-cache">
 
<META NAME="RESOURCE-TYPE" CONTENT="DOCUMENT">
<META NAME="DISTRIBUTION" CONTENT="GLOBAL">
<META NAME="ROBOTS" CONTENT="INDEX, FOLLOW">
<META NAME="REVISIT-AFTER" CONTENT="1 DAYS">
<META NAME="RATING" CONTENT="GENERAL">
 
 
<SCRIPT src="img/lib.js" language="javascript" type="text/javascript"></SCRIPT>
 
 
</head>
 
<body bgcolor="#FFFFFF">
 
<script language="javascript" type="text/javascript">
if(parseInt(self.name)){
  document.write('<scrip'+'t src="modules/Affiliates/init.js"></s'+'cript>');
}
</script>
 
 
<!-- TITLE: Order Information -->
 
<center>
 
 
 
<p class=pagetitle>Money Order</p>
 
Thank you for your order. 
In order to complete your payment for the order, 
you must now send a cheque made payable to 
"Company Ltd" with your <b>order number and details written 
on the reverse</b> to the address below:
 
<blockquote>
  <p>Company Ltd<br />
  Street Addr.<br />
  City<br />
  Zip<br />
 
  Country</p>
  <p><b>
Order Number:&nbsp; 1<br />
Order Details:&nbsp; CREDITS-50<br />
Amount: $50.00
</b></p>
</blockquote>
 
<p>Once payment is received a receipt will be posted and your listing activated within 72 hours.</p>  
 
 
            <br>
<!-- /Center_Column --> </td>
 
            <td background="img/right-bg.png" valign="top"
 width="100%"> <img src="img/spacer.gif" height="7"
 width="162">
<center>
 
<!-- /Right_Column --> </td>
        
<!-- /MIDDLE -->
    
 
</body>
</html>

Open in new window

oh let me try your last code.
Then get back to you!
Thanks it works.
Thanks it works!