Click to See Complete Forum and Search --> : input integers


fisk
03-19-2003, 06:49 AM
Hello...I just want basic code to input two numbers and display to the screen and then print them out and then I want to do a function to calculate and then validate them for errors. For example the sum and the difference. I am new and just need to get my self started. Thanks

fisk
03-19-2003, 08:52 PM
please help me...I want to input two integers that are displayed to the screen the following information the sum (first and second) the difference (first -second) The quotient (first / second, second cannot be 0) etc. and then print the results out in single file and then write seperate functions to determine each of the functions and then call another function to return message "invalid attempt to divide by 0" in a single alert and handle any non-numeric input . Can anyone get me started. I'm very new at this and not a programmer. Thank you thank you .

fisk
03-19-2003, 09:27 PM
Yes all I need is an example of this problem. Please help me...I want to input two integers that are displayed to the screen the following information the sum (first and second) the difference (first -second) The quotient (first / second, second cannot be 0) etc. and then print the results out in single file and then write seperate functions to determine each of the functions and then call another function to return message "invalid attempt to divide by 0" in a single alert and handle any non-numeric input . Can anyone get me started. I'm very new at this and not a programmer. Thank you thank you .

fisk
03-19-2003, 11:26 PM
Why doesn't anyone reply to me?

Jona
03-19-2003, 11:29 PM
Here... something like this maybe...

<html><head><title>Calculator</title>
<script>
function calculate(){
var slct = document.frm.slct[document.frm.slct.options.selectedIndex].value;
var answer = null;
if(slct=="add"){
a1.innerText = parseInt(document.frm.txt1.value)+parseInt(document.frm.txt2.value);
}
if(slct=="subt"){
a1.innerText = parseInt(document.frm.txt1.value)-parseInt(document.frm.txt2.value);
}
if(slct=="mult"){
a1.innerText = parseInt(document.frm.txt1.value)*parseInt(document.frm.txt2.value);
}
if(slct=="divide"){
a1.innerText = parseInt(document.frm.txt1.value)/parseInt(document.frm.txt2.value);
}
}
</script>
</head><body>
<form name="frm">
<input type=text name="txt1">
<select size=1 name="slct">
<option value="add" selected>Add
<option value="subt">Subtract
<option value="mult">Multiply
<option value="divide">Divide
</select>
<input type=text name="txt2"><br><br>
<input type=button onclick="calculate()" value="Calculate">
</form>
<div id="a1">
</div>
</body></html>

fisk
03-19-2003, 11:37 PM
Can anyone see this?

Jona
03-19-2003, 11:38 PM
They have been.

Code One
03-20-2003, 02:39 AM
So you want to add 1+1 have it displayed on screen, then equal it have that displayed on screen and then print it? If thats it then just make a calculator that displays the outputs and inputs in a frame, and use the class=noprint in the form or table, including everything else other than the frame or table your inout and output displays, add a print button, and a way you go.


Code One


edit: oh yeah about the alert, dont bother the display should show undefined, when someone does that, youd just be reinventing the wheel.

fisk
03-20-2003, 06:59 AM
Why does my envelope way on the left side look different than everyone else's. It looks like it has a hole in it?? Is this why no one is replying to my other questions? What am I doing wrong?

fisk
03-21-2003, 06:58 AM
Thanks so much everyone for helping with the calculator but was just also wondering if someone could help me finish with a min of the two numbers max of the two numbers and average. I put it in in words but doesn't work. Thank you so much. Here is what I have. I know something isn't right just can't figure it out. I did get a print button added. Its kinda fun.


<html>
<head>
<body background=back4.gif>
<title>WebProgramming 1
</title>
<script>
function calculate()
{
var slct = document.frm.slct[document.frm.slct.options.selectedIndex].value;
var answer = null;
if(slct=="+")
{
a1.innerText =
parseInt(document.frm.txt1.value)+parseInt(document.frm.txt2.value);
}
if(slct=="-")
{
a1.innerText =
parseInt(document.frm.txt1.value)-parseInt(document.frm.txt2.value);
}
if(slct=="*"){
a1.innerText =
parseInt(document.frm.txt1.value)*parseInt(document.frm.txt2.value);
}
if(slct=="/"){
a1.innerText =
parseInt(document.frm.txt1.value)/parseInt(document.frm.txt2.value);
}
if(slct=="%")
{
a1.innerText =
parseInt(document.frm.txt1.value)%parseInt(document.frm.txt2.value);
}
if(slct=="avg")
{
a1.innerText =
parseInt(document.frm.txt1.value) parseInt(document.frm.txt2.value);
}
if(slct=="min(a,b)"
{
a1.innerText =
parseInt(document.frm.txt1.value)min(a,b)parseInt(document.frm.txt2.value);
}
if(slct=="max")
{
a1.innerText =
parseInt(document.frm.txt1.value)"max"parseInt(document.frm.txt2.value);
}

}

</script>
</head>

<body>
<form name="frm">
<input type=text name="txt1">
<select size=1 name="slct">
<option value="+" selected>+
<option value="-">-
<option value="*">*
<option value="/">/
<option value="%">%
<option value="avg">average
<option value="min">minimum
<option value="max">maximum
</select>
<input type=text name="txt2"><br><br>
<input type=button onclick="calculate()" value="Calculate">
<input type=button onclick="print()" value="Print">
</form>
<div id="a1">
</div>
</body>
</html>