Math on page...how to?

  • Thread starter Thread starter KSL
  • Start date Start date
K

KSL

I've been asked to add a page that will have a form box. The viewer will
be asked to key in a dollar figure and the page is to divide the number
and give the results.

Can anyone point me to a "how-to" or even some pointers here? I will
find out exactly what the equation is tomorrow.

Thanks ... Again

Kevin
 
KSL said:
I've been asked to add a page that will have a form box. The viewer
will be asked to key in a dollar figure and the page is to divide the
number and give the results.

Can anyone point me to a "how-to" or even some pointers here? I will
find out exactly what the equation is tomorrow.

Thanks ... Again

Kevin

Try this

In the form
<form id ="form1">
<input type="text" id="val1" value="10"/>Dollar value<br/>
<input type="text" id="val2" value="3" />Divide by<br/>
<input type="text" id="result" size="10" />Result of Division
........................
<input type="button" id="submit" value=" Send "onclick="sendform()" />

Add
function sendform()
{
with (document.form1)
{result.value = (+val1.value) / (+val2.value)}
/* other stuff you want to do */
}

Change values in val1 and val2 and click submit.
The value in "Result of Division" will alter.

BTW,
If you need to know where to place the function, please post back.
 
Trevor,
This looks promising. I tried it a couple of times, but I guess its
still early and I haven't had my coffee yet. I get the form boxes, but I
also get half the code visible on the page.

Where does it go?

Thanks!
 
KSL said:
Trevor,
This looks promising. I tried it a couple of times, but I guess its
still early and I haven't had my coffee yet. I get the form boxes,
but I also get half the code visible on the page.

Where does it go?

Thanks!

This is the entire code which tests OK:

<head>
<script type="text/javascript">
function sendform()
{
with (document.form1)
{ result.value = (+val1.value) / (+val2.value) }
// other stuff here
}
</script>
</head>
<body>
<form name="form1" action="">
<table>
<tr>
<td>Dollar value: </td>
<td><input type="text" id="val1" value="10"/></td>
</tr>
<tr>
<td>Divide by: </td>
<td><input type="text" id="val2" value="3" /></td>
</tr>
<tr>
<td>Result of Division: </td>
<td><input type="text" id="result" size="20" /></td>
</tr>
</table>
<input type="button" id="submit" value=" Send "onclick="sendform()" />
</form>
</body>
</html>

I made an error - the form tag must be name="form1", which surprises me as I thought id="xx" could replace name="xx" just about
anywhere.
Ah well, I htink I have to go back to school and learn more about DOM ;-))
 
Back
Top