...

View Full Version : Functions in forms



gowans007
12-19-2003, 11:53 PM
I am trying to make a page which wis sort of a budget planner,
It works out people inputs and adds them up and shows the results live.
But
The entered information also needs to be saved to a mySQL db via php and a form however I have a script working either entering the data to the db or adding up the data with javascript but the moment i try to put the javascript withing the for so the info can be saved it wont work.

how can I fix this,
any help would be much aprichiated as I have hit a brick wall.

I HAVE ATACHED THE WORKING JAVACRIPT BUT NEED TO KNOW HOW TO CHANGE IT TO PUT IT WITHIN A FORM AND STILL WORK.

Thankyou,
David
gowans007@yahoo.com



<html>
<head>
<script language="javascript">
<!--
function addIt(){
var value1 = document.adder.in_sloan.value
var value2 = document.adder.in_parent_cont.value
var value3 = document.adder.in_pt_job.value
var value4 = document.adder.in_other.value
document.adder.output.value = parseFloat(value1) + parseFloat(value2) + parseFloat(value3) + parseFloat(value4)

var value5 = document.adder.in_sloan2.value
var value6 = document.adder.in_parent_cont2.value
var value7 = document.adder.in_pt_job2.value
var value8 = document.adder.in_other2.value
document.adder.output2.value = parseFloat(value5) + parseFloat(value6) + parseFloat(value7) + parseFloat(value8)

document.adder.finalout.value = parseFloat(value1) + parseFloat(value2) + parseFloat(value3) + parseFloat(value4) + parseFloat(value5) + parseFloat(value6) + parseFloat(value7) + parseFloat(value8)

}
//-->
</script>
</head>
<body>

<FORM NAME="adder">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td> </td>
<td><table width="52%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><input name="in_sloan" type="text" onChange="addIt()" value=0 size=4>
var1 </td>
</tr>
<tr>
<td><input name="in_parent_cont" type="text" onChange="addIt()" value=0 size=4>
var2 </td>
</tr>
<tr>
<td><input name="in_pt_job" type="text" onChange="addIt()" value=0 size=4>
var3</td>
</tr>
<tr>
<td><input name="in_other" type="text" onChange="addIt()" value=0 size=4>
var4 </td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<td><input type="text" name="output" size="6">
<strong> tot </strong></td>
</tr>
</table></td>
<td> </td>
<td><table width="44%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><input name="in_sloan2" type="text" onChange="addIt()" value=0 size=4>
var5</td>
</tr>
<tr>
<td><input name="in_parent_cont2" type="text" onChange="addIt()" value=0 size=4>
var6</td>
</tr>
<tr>
<td><input name="in_pt_job2" type="text" onChange="addIt()" value=0 size=4>
var7</td>
</tr>
<tr>
<td><input name="in_other2" type="text" onChange="addIt()" value=0 size=4>
var8</td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<td><input type="text" name="output2" size="6">
<strong>tot2</strong></td>
</tr>
</table></td>
<td><input name="finalout" type="text" id="finalout" size="6">
<strong>final tot </strong></td>
</tr>
</table>
</FORM>

</body>
</html>

Kor
12-20-2003, 10:30 AM
as far as I can see, there is nothing wrong with the HTML or javascript here... The input values should go to that server-side application you said you have it... Of course, if you specify that in the form's tag....

<form name="adder" method="post" action="URL_here">



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum