Jump to content
buildmy401k

Form Auto Submit And Calc Js

Recommended Posts

Hello I am trying to perform two calculations and autosumbit the page, however only the second calculation is being performed when the page is autosubmitted. Please advise.

 

<SCRIPT LANGUAGE="JavaScript">
 
 function calculate()
 {
   var v_Current_Plan = parseFloat(document.getElementById("InsertRecordCurrent_Plan").value);
   var v_Current_Fee = parseFloat(document.getElementById("InsertRecordCurrent_Fee").value);
   var v_Rate= .08;
   var v_total  = (((v_Current_Plan * v_Rate) + v_Current_Plan) - (((v_Current_Plan * v_Rate) + v_Current_Plan) * v_Current_Fee));
   document.getElementById("InsertRecordCurrent_Plan").value = Math.round(v_total);
 }
 
 {
   var v_New_Plan = parseFloat(document.getElementById("InsertRecordNew_Plan").value);
   var v_New_Fee = parseFloat(document.getElementById("InsertRecordNew_Fee").value);
   var v_Rate= .08;
   var v_total  = (((v_New_Plan * v_Rate) + v_New_Plan) - (((v_New_Plan * v_Rate) + v_New_Plan) * v_New_Fee));
   document.getElementById("InsertRecordNew_Plan").value = Math.round(v_total);
 }
 
 /* On submitting the webform, the function calculate is executed */
 document.getElementById("caspioform").onsubmit=calculate;
 
</SCRIPT>
<SCRIPT LANGUAGE="JavaScript">
 
 function calculate()
 {
   var v_Current_Plan = parseFloat(document.getElementById("InsertRecordCurrent_Plan").value);
   var v_Current_Fee = parseFloat(document.getElementById("InsertRecordCurrent_Fee").value);
   var v_Rate= .08;
   var v_total  = (((v_Current_Plan * v_Rate) + v_Current_Plan) - (((v_Current_Plan * v_Rate) + v_Current_Plan) * v_Current_Fee));
   document.getElementById("InsertRecordCurrent_Plan").value = Math.round(v_total);
 }
 
 {
   var v_New_Plan = parseFloat(document.getElementById("InsertRecordNew_Plan").value);
   var v_New_Fee = parseFloat(document.getElementById("InsertRecordNew_Fee").value);
   var v_Rate= .08;
   var v_total  = (((v_New_Plan * v_Rate) + v_New_Plan) - (((v_New_Plan * v_Rate) + v_New_Plan) * v_New_Fee));
   document.getElementById("InsertRecordNew_Plan").value = Math.round(v_total);
 }
 
 /* On submitting the webform, the function calculate is executed */
 document.getElementById("caspioform").onsubmit=calculate;
 
 
</SCRIPT>
 
<script>
  if(document.getElementById("caspioform")) {
  document.getElementById("caspioform").style.display = 'none';
  setTimeout('document.forms["caspioform"].submit()',0); } 
 
</script>

Share this post


Link to post
Share on other sites

Good morning Allen,


 


How are you doing?


 


In Java Script, "{" means "Start" and "}" means "Finish". So, if you want to do several actions in a function, I think, it's better don't write "Finish" and then "Start" again between them, the function doesn't execute any code after the "Finish" sign.


 


In setTimeout('document.forms["caspioform"].submit()',0); }, "0" means how long a DataPage waits before auto submits. It's better to use "1000", at least "100" milliseconds, then you allow a DataPage to load and then autosubmit it.


 


And if you want to call another function before autosubmit, you can write the same code but for another function:


setTimeout('calculate()',500); }


 


Then the whole code will be like:



<SCRIPT LANGUAGE="JavaScript">
 
 function calculate()
 {
   var v_Current_Plan = parseFloat(document.getElementById("InsertRecordCurrent_Plan").value);
   var v_Current_Fee = parseFloat(document.getElementById("InsertRecordCurrent_Fee").value);
   var v_Rate= .08;
   var v_total  = (((v_Current_Plan * v_Rate) + v_Current_Plan) - (((v_Current_Plan * v_Rate) + v_Current_Plan) * v_Current_Fee));
   document.getElementById("InsertRecordCurrent_Plan").value = Math.round(v_total);

   var v_New_Plan = parseFloat(document.getElementById("InsertRecordNew_Plan").value);
   var v_New_Fee = parseFloat(document.getElementById("InsertRecordNew_Fee").value);
   var v_Rate= .08;
   var v_total  = (((v_New_Plan * v_Rate) + v_New_Plan) - (((v_New_Plan * v_Rate) + v_New_Plan) * v_New_Fee));
   document.getElementById("InsertRecordNew_Plan").value = Math.round(v_total);
 }
 
if(document.getElementById("caspioform")) {
document.getElementById("caspioform").style.display = 'none';
setTimeout('calculate()',500);
setTimeout('document.forms["caspioform"].submit()',1000); }
 
</script>

I'm learning the JavaScript now, so, I'll be grateful, if you tell me if the code works.


 


Have a nice day!


Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...