Thread: Form does multiple calulations
Results 1 to 4 of 4
Related
-
Multiple drop down form woes Forum: Javascript Forum
Replies: 1 -
Multiple drop down form woes Forum: HTML Forum
Replies: 0 -
Multiple Menus on the Same Form? Forum: HTML Forum
Replies: 11 -
multiple submit buttons in single form Forum: HTML Forum
Replies: 7 -
Multiple Form Inputs Forum: HTML Forum
Replies: 3
-
10-12-2007, 12:28 PM #1
Form does multiple calulations
I have a form that needs to do multiple calculations from one button. I've got a script to do some of the calculations but as soon as I add the third field it fails entirely. Can someone look at the script and tell me where things have gone horribly wrong?
The form is supposed to add Field 1 &1 and divide them by hours worked and it's supposed to divide field 3 by the hours worked.
Thanks
Code:<html> <head> <title></title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <style type="text/css"> .m span { color:#f00; font-size:18px; } </style> <script type="text/javascript"> var df; window.onload=function(){ df=document.forms[0]; df[1].focus(); df[5].onclick=function() { doSums(); } df[8].onclick=function() { df[1].focus(); } } function doSums(){ hours=parseFloat(df[1].value); if(isNaN(hours)) { alert('please enter hours'); df[1].value=''; df[1].focus(); return; } else { df[2].focus(); } fld1=parseFloat(df[2].value); if(isNaN(fld1)) { alert('please enter field 1'); df[2].value=''; df[2].focus(); return; } else { df[3].focus(); } fld2=parseFloat(df[3].value); if(isNaN(fld2)) { alert('please enter field 2'); df[3].value=''; df[3].focus(); return; else { df[4].focus(); } fld2=parseFloat(df[4].value); if(isNaN(fld3)) { alert('please enter field 3 cost'); df[4].value=''; df[4].focus(); return; } df[6].value=(fld1+fld2).toFixed(2); df[7].value=((fld1+fld2)/hours).toFixed(2); df[8].value='$ '+((fld3)/hours).toFixed(2); } </script> </head> <body> <form name="qdbform" method="post" encType="multipart/form-data" action="https://www.quickbase.com/db/bcuh33rwr?act=API_AddRecord" onsubmit="return validateForm(this)"> <table> <tr> <td class="m"><span>* </span>Total Hours Worked</td> <td class="m"><input type="hidden" name="fform" value="1"/><input type="text" size="10" name="_fid_24" /></td> </tr> <tr> <td class="m"><span>* </span>Field 1</td> <td class="m"><input type="text" size="10" name="_fid_25" ></td> </tr> <tr> <td class="m"><span>* </span>Field 2</td> <td class="m"><input type="text" size="10" name="_fid_26" /></td> </tr> <tr> <td class="m"><span>* </span>Field 3</td> <td class="m"><input type="text" size="10" name="_fid_26" /></td> </tr> <tr> <td class="m"><input type="button" value="calculate"/></td></tr> <td class="m"><span>* </span>Total of Field 1 and 2</td> <td class="m"><input type="text" size="10" name="_fid_27" readonly="readonly" /></td> </tr> <tr> <td class="m"><span>* </span>Total of Fields 1and 2 divided by Work Hours</td> <td class="m"><input type="text" size="10" name="_fid_28" readonly="readonly"/></td> </tr> <tr> <td class="m"><span>* </span>Total of Field 3 divided by Work Hours</td> <td class="m"><input type="text" size="10" name="_fid_28" readonly="readonly"/></td> </tr> <tr> <td class="m"><input type="reset" value="clear fields"/ ><input type=submit value=Save></td> </tr></table> </form> </body> </html>
-
10-12-2007, 06:07 PM #2bald headed old fart
Status- Offline
Join Date- Aug 2003
Location- chertsey, a small town 25 miles south west of london, england.
Posts- 739
Re: Form does multiple calulations
Hi there Lorib01,
that javascript has a certain familiarity.
Here is the page corrected and validated...
Code:<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <title></title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <style type="text/css"> .m span { color:#f00; font-size:18px; } </style> <script type="text/javascript"> var df; window.onload=function(){ df=document.forms[0]; df[1].focus(); df[5].onclick=function() { doSums(); } df[8].onclick=function() { df[1].focus(); } } function doSums(){ hours=parseFloat(df[1].value); if(isNaN(hours)) { alert('please enter hours'); df[1].value=''; df[1].focus(); return; } else { df[2].focus(); } fld1=parseFloat(df[2].value); if(isNaN(fld1)) { alert('please enter field 1'); df[2].value=''; df[2].focus(); return; } else { df[3].focus(); } fld2=parseFloat(df[3].value); if(isNaN(fld2)) { alert('please enter field 2'); df[3].value=''; df[3].focus(); return; } else { df[4].focus(); } fld3=parseFloat(df[4].value); if(isNaN(fld3)) { alert('please enter field 3 cost'); df[4].value=''; df[4].focus(); return; } df[6].value=(fld1+fld2).toFixed(2); df[7].value=((fld1+fld2)/hours).toFixed(2); df[8].value='$ '+((fld3)/hours).toFixed(2); } </script> </head> <body> <form name="qdbform" method="post" encType="multipart/form-data" action="https://www.quickbase.com/db/bcuh33rwr?act=API_AddRecord" onsubmit="return validateForm(this)"> <table> <tr> <td class="m"><span>* </span>Total Hours Worked</td> <td class="m"><input type="hidden" name="fform" value="1"><input type="text" size="10" name="_fid_24"></td> </tr><tr> <td class="m"><span>* </span>Field 1</td> <td class="m"><input type="text" size="10" name="_fid_25"></td> </tr><tr> <td class="m"><span>* </span>Field 2</td> <td class="m"><input type="text" size="10" name="_fid_26"></td> </tr><tr> <td class="m"><span>* </span>Field 3</td> <td class="m"><input type="text" size="10" name="_fid_26"></td> </tr><tr> <td class="m"><input type="button" value="calculate"></td> </tr><tr> <td class="m"><span>* </span>Total of Field 1 and 2</td> <td class="m"><input type="text" size="10" name="_fid_27" readonly="readonly"></td> </tr><tr> <td class="m"><span>* </span>Total of Fields 1and 2 divided by Work Hours</td> <td class="m"><input type="text" size="10" name="_fid_28" readonly="readonly"></td> </tr><tr> <td class="m"><span>* </span>Total of Field 3 divided by Work Hours</td> <td class="m"><input type="text" size="10" name="_fid_28" readonly="readonly"></td> </tr><tr> <td class="m"><input type="reset" value="clear fields"><input type="submit" value="Save"></td> </tr></table> </form> </body> </html>
-
10-15-2007, 07:06 AM #3
Re: Form does multiple calulations
I knew it would look familiar. Thank you so much for your help, I've learned a great deal from you.
-
10-15-2007, 10:30 AM #4bald headed old fart
Status- Offline
Join Date- Aug 2003
Location- chertsey, a small town 25 miles south west of london, england.
Posts- 739
Re: Form does multiple calulations
No problem, you're very welcome.
Cloudjiffy- PaaS for Developers
10-05-2020, 12:30 AM in Web Hosting Forum