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,
majdolyanAsked:
Who is Participating?
 
hankknightConnect With a Mentor Commented:
Replace the snippet you posted with this.  If it does not work then you will have to show me the HTML that the template outputs, NOT the template.
<!-- TITLE: Order Information -->
<span id="value2" style="display: none">3.75</span>
<blockquote>
<font color=red><b>
Order Number:&nbsp; ##id##<br />
Order Details:&nbsp; ##term_out##<br />
Amount: ##CURR_SIGN##<span id="value1">##total##</span>
</b></font></p>
</blockquote>
 
<p><strong>Answer: <span id="answer"></span></strong></p>
 
<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> 

Open in new window

0
 
stormistCommented:
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
0
 
hankknightCommented:
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

0
Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

 
majdolyanAuthor Commented:
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
0
 
majdolyanAuthor Commented:
FYI

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

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

Instead of this:
##12##

?
0
 
majdolyanAuthor Commented:
No, it's encrypted!
0
 
hankknightCommented:
Can you post all or at least some of the HTML that the PHP outputs so I can see what it looks like?
0
 
majdolyanAuthor Commented:
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

0
 
hankknightCommented:
That is a snippet of the template, but what does the HTML that the template outputs look like?
0
 
majdolyanAuthor Commented:
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

0
 
majdolyanAuthor Commented:
oh let me try your last code.
Then get back to you!
0
 
majdolyanAuthor Commented:
Thanks it works.
0
 
majdolyanAuthor Commented:
Thanks it works!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.