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

add two numbers and subtract one

Status
Not open for further replies.

dmccallum

Programmer
Jan 5, 2001
90
US
I have a page on geocities that I would like to add a box where someone could insert an installation number and then my page would display the (installation number + 4) - 25 for their serial number. But I can't find an example anywhere to help me out. Can anyone explain?
 
<SCRIPT LANGUAGE=&quot;JavaScript&quot;>
function calculate()
{
x = parseInt(document.installation.number.value)
x = x + parseInt(4) - parseInt(25)
document.installation.number.value=x
}
</SCRIPT>


<form name=&quot;installation&quot; method=&quot;POST&quot; action=&quot;test.html&quot;>
<input type=&quot;text&quot; name=&quot;number&quot; value=&quot;&quot;>
<BR>
<BR>
<img onClick=&quot;calculate()&quot; src=&quot;&quot;>

</form>
 
what's the problem???
[tt]
<html>
<body>
<form name=form1>
<input type=text name=calc1 value=&quot;&quot; >
<input type=button value=&quot;calculate&quot; onclick=&quot;form1.calc1.value-=21&quot;>
</form>
</body>
</html>
[/tt]
 
starway,

When I tried your example I received an invalid path error message. Why?
 
Invalid path? Path to what???
It seems that there's some error without any connection to the code I gave you.
 
You're right. I found the solution to that one by saving the code but how do I get the result of the calculation to display? Can I create another text box to the right of the calculation button that would display the result after hitting the button?
 
Well, in my example I thought that you want to see the result in the same text field, that is how I understood your question.
If you want to see the result in another text field - yes sure you can!

Here's a new one:

<html>
<body>
<form name=form1>
input:
<input type=text name=input value=&quot;&quot;>
output:
<input type=text name=output value=&quot;&quot;>
<br>
<input type=button value=&quot;calculate&quot; onclick=&quot;form1.output.value=form1.input.value-21&quot;>

</form>
</body>
</html>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top