SEARCH

The How-To Geek Forums Have Migrated to Discourse



Join the Discussion at discuss.howtogeek.com

How-To Geek Forums / Geek Stuff

Stumped On This Project

(12 posts)
  • Started 8 months ago by DeLoreanDrifter
  • Latest reply from Lighthouse
  • Topic Viewed 354 times

DeLoreanDrifter
DeLoreanDrifter
Posts: 25

How can I make 2 numbers if entered in the provided textboxes add up?
For example if I enter two 5's then the result will show up below..
5+5=10 ..like so.

..my code so far (as follows):

<html>
<body>

<body bgcolor="#DDA0DD">

<h1>"CALCULATION"</h1>

<form method="POST">

1st Number:<input type="text" name="num1"/>

<br>
2nd Number:<input type="text" name="num2"/>

<br>
<input type="submit" name="submit" value="CLICK ME .. NOW!"/>

<br>
<h1><B><font color="BLUE">GETTING THERE SLOWLY BUT SURELY BABY!!! :)</B></h1>

</form>

<p></p>

</body>
</html>

Edit by mod - please mind your language ...

Posted 8 months ago #
Top
 
Enthusiast
Enthusiast
Posts: 566

HTML is not a programming language. It provides constructs for formatting web pages. You will need some way of manipulating the information you have set up the HTML to get from the user, such as PHP, .NET, etc.

Posted 8 months ago #
Top
 
DeLoreanDrifter
DeLoreanDrifter
Posts: 25

I totally understand but I did it as a way that I could view it in the browser, it can't be done in HTML at all? Is what ur saying? :-/

Posted 8 months ago #
Top
 
dbug71
Posts: 1

<?php
$value1 = $_POST['value1'];
$value2 = $_POST['value2'];
?>
<html>
<title>PHP - Add two numbers</title>
<body>
<form action="addtwonumbers.php" method="post">
<input type="text" name="value1" value="0" />
<input type="text" name="value2" value="0" />
<input type="submit" value="Calculate values"/>
</form>
Answer : <?php echo ($value1 + $value2); ?>
</body>
</html>

Posted 8 months ago #
Top
 
KneeDeep
Posts: 6

You would probably need some kind of 'code behind' such as C# or vb.net if you look at it from an ASP context.

Posted 8 months ago #
Top
 
RRRoman
Posts: 53

Can't it be solved with a javascript function? it isn't that complicated and it frees you from the need to support the languages such as php or c#.

EDIT:

<html>
<head>
<script>
function add()
{
document.getElementById("sum").value = Number(document.getElementById("num1").value) + Number(document.getElementById("num2").value);
}
</script>
</head>
<body>
<body>

<body bgcolor="#DDA0DD">

<h1>"CALCULATION"</h1>
1st Number:<input type="text" id="num1"/>

<br>
2nd Number:<input type="text" id="num2"/>
<br>
Sum: <input type="text" id="sum"/>
<br>
<button onclick="add()">CLICK ME NOW</button>
<br>

<h1><B><font color="BLUE">GETTING THERE SLOWLY BUT SURELY BABY!!! :)</B></h1>
</form>

<p></p>

</body>
</html>

this code should do the trick
Note: I have not tested it so give it a try and let me know how well it runs.

Posted 8 months ago #
Top
 
RRRoman
Posts: 53

just saw that I have a double <body> tag and then there is a <body bgcolor ...> so I think you can remove both preceding <body> tags.

Posted 8 months ago #
Top
 
Enthusiast
Enthusiast
Posts: 566

That code does not produce a result in my browser, IE8.

Posted 8 months ago #
Top
 
RRRoman
Posts: 53

Just tested it myself, works fine here. I am using Google Chrome... Check the IE8 settings and see if you have javascript enabled.

Posted 8 months ago #
Top
 
RRRoman
Posts: 53

Ok I've just tested it on my IE and it does not work there either... checking for solutions.

Posted 8 months ago #
Top
 
RRRoman
Posts: 53

Yeah the problem is in the IE (I was using IE9), anyway on start it says that it has blocked all scripts and ActiveX controls so when I click on allow blocked content the script works fine... so check the security settings and see if you're blocking all scripts from being executed.

Posted 8 months ago #
Top
 
Lighthouse
Lighthouse
Posts: 13598

RRRoman, you do have 30 minutes editing time on your posts. Please use it.

Posted 8 months ago #
Top
 



Topic Closed

This topic has been closed to new replies. Please create a new topic instead.


Create New Topic Return to Forum