xcusmwah
asked on
Simple Javascript Validation & "Sum" help
Just starting out with javascript. I figured out how to get the fields to sum but wanted to see how someone else would do it. I would also like to see how to validate the form so that the dollar sign and decimal point gets added in to the currency fields but still "add" the result to the total field with the dollar sign. It would be great to have it so only numeric data can be entered in. Thank you...below is what I have...feel free to tweak anything you wish but if you could leave the field names the same I would appreciate it.
<html>
<head>
<script language="JavaScript">
function addForm(){
document.form.req_TotalRai sedforWeek .value = document.form.req_TotalFun dsRaisedat Registers. value * 1 + document.form.req_WeekendE ventTotalA mountRaise d.value *1;
</script>
</head>
<body>
<form enctype="multipart/form-da ta" name="form">
<center>
<table WIDTH="600" BORDER=0 align="left" >
<tr>
<td HEIGHT="29" colspan="2">
<h1>Javascript Test Form</h1></td>
</tr>
<tr>
<td width="55%" height="28" bgcolor="#FFFFCC"><font color="#000000"><b>Person Submitting: <font color="#FF0000">*</font></ b> </font></td>
<td width="45%">
<div align="left">
<input name="req_PersonSubmitting " id="req_PersonSubmitting">
</div></td>
</tr>
<tr>
<td height="28" nowrap bgcolor="#FFFFCC"><strong> Total Funds Raised at
Registers (Canisters):<font color="#000000"><font color="#FF0000">*</font></ font></str ong></td>
<td>
<div align="left">
<input name="req_TotalFundsRaised atRegister s" id="req_TotalFundsRaisedat Registers" onChange="addForm();" size="6" maxlength="6">
</div></td>
</tr>
<tr>
<td height="28" bgcolor="#FFFFCC"><strong> Weekend
Event Description: <font size="2">(if none, type none)</font><font color="#000000"><font color="#FF0000">*</font></ font></str ong></td>
<td>
<div align="left">
<input name="req_WeekendEventDesc ription" id="req_WeekendEventDescri ption" onChange="addForm();" size="20" maxlength="6">
</div></td>
</tr>
<tr>
<td bgcolor="#FFFFCC"><strong> Weekend Event Total Amount Raised:<font color="#000000"><font color="#FF0000">*</font></ font></str ong></td>
<td bgcolor="#FFFFFF">
<div align="left">
<input name="req_WeekendEventTota lAmountRai sed" id="req_WeekendEventTotalA mountRaise d" onChange="addForm();" size="6" maxlength="6">
</div></td>
</tr>
<tr bgcolor="#FFFFFF">
<td height="3" colspan="2"><br></td>
</tr>
<tr>
<td height="28" nowrap bgcolor="#FFFFCC"><strong> <font color="#000000">Total Raised for Week: <font size="2">(automatically
calculated)</font><font color="#FF0000">*</font></ font></str ong></td>
<td>
<div align="left">
<input name="req_TotalRaisedforWe ek" id="req_TotalRaisedforWeek " size="7" maxlength="7" onFocus="blur()">
</div></td>
</tr>
<tr>
<td height="28" colspan="2"> </td>
</tr>
<tr>
<td height="28" colspan="2"><input type="submit" value="Submit" onClick="addForm();" ></td>
</tr>
</table>
<br>
</center>
</form>
</body>
</html>
<html>
<head>
<script language="JavaScript">
function addForm(){
document.form.req_TotalRai
</script>
</head>
<body>
<form enctype="multipart/form-da
<center>
<table WIDTH="600" BORDER=0 align="left" >
<tr>
<td HEIGHT="29" colspan="2">
<h1>Javascript Test Form</h1></td>
</tr>
<tr>
<td width="55%" height="28" bgcolor="#FFFFCC"><font color="#000000"><b>Person Submitting: <font color="#FF0000">*</font></
<td width="45%">
<div align="left">
<input name="req_PersonSubmitting
</div></td>
</tr>
<tr>
<td height="28" nowrap bgcolor="#FFFFCC"><strong>
Registers (Canisters):<font color="#000000"><font color="#FF0000">*</font></
<td>
<div align="left">
<input name="req_TotalFundsRaised
</div></td>
</tr>
<tr>
<td height="28" bgcolor="#FFFFCC"><strong>
Event Description: <font size="2">(if none, type none)</font><font color="#000000"><font color="#FF0000">*</font></
<td>
<div align="left">
<input name="req_WeekendEventDesc
</div></td>
</tr>
<tr>
<td bgcolor="#FFFFCC"><strong>
<td bgcolor="#FFFFFF">
<div align="left">
<input name="req_WeekendEventTota
</div></td>
</tr>
<tr bgcolor="#FFFFFF">
<td height="3" colspan="2"><br></td>
</tr>
<tr>
<td height="28" nowrap bgcolor="#FFFFCC"><strong>
calculated)</font><font color="#FF0000">*</font></
<td>
<div align="left">
<input name="req_TotalRaisedforWe
</div></td>
</tr>
<tr>
<td height="28" colspan="2"> </td>
</tr>
<tr>
<td height="28" colspan="2"><input type="submit" value="Submit" onClick="addForm();" ></td>
</tr>
</table>
<br>
</center>
</form>
</body>
</html>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.