Jump to content
lmooring

Multiple Javascripts Only One Works

Recommended Posts

I am attempting to use a simply JavaScript to create an extended cost on a submission form. I have a few lines of this. When I add the JavaScript, only the last script works. Almost like it is canceling out the prior. I do not know how to make them both work or how to combine them into one larger script.

Any assistance would be greatly appreciated. My lines of code are inserted below. They work individually but not both at once on the same submission form.

<SCRIPT LANGUAGE="JavaScript">

 function calculateextcost1()
 {
   var v_item1 = parseFloat(document.getElementById("InsertRecordITEMUNITS1").value);
if (isNaN(v_item1)) v_item1  = 0;
   var v_cost1  = parseFloat(document.getElementById("InsertRecordITEMCOST1").value);
if (isNaN(v_cost1)) v_cost1  = 0;
    var v_extcost1 = (v_item1 * v_cost1);
   document.getElementById("InsertRecordITEMEXTCOST1").value = (v_extcost1);

 }

 /* On submitting the webform, the function calculate is executed */
 document.getElementById("caspioform").onchange = calculateextcost1;

</SCRIPT>

<SCRIPT LANGUAGE="JavaScript">

 function calculateextcost2()
 {
   var v_item2 = parseFloat(document.getElementById("InsertRecordITEMUNITS2").value);
if (isNaN(v_item2)) v_item2  = 0;
   var v_cost2  = parseFloat(document.getElementById("InsertRecordITEMCOST2").value);
if (isNaN(v_cost2)) v_cost2  = 0;
    var v_extcost2 = (v_item2 * v_cost2);
   document.getElementById("InsertRecordITEMEXTCOST2").value = (v_extcost2);

 }

 /* On submitting the webform, the function calculate is executed */
 document.getElementById("caspioform").onchange = calculateextcost2;

</SCRIPT>

 

Share this post


Link to post
Share on other sites

You need to combine both scripts in one no need to have two:

<SCRIPT LANGUAGE="JavaScript">

 function calculateextcost1()
 {
   var v_item1 = parseFloat(document.getElementById("InsertRecordITEMUNITS1").value);
if (isNaN(v_item1)) v_item1  = 0;
   var v_cost1  = parseFloat(document.getElementById("InsertRecordITEMCOST1").value);
if (isNaN(v_cost1)) v_cost1  = 0;
    var v_extcost1 = v_item1 * v_cost1;
   document.getElementById("InsertRecordITEMEXTCOST1").value = v_extcost1;

 }

  function calculateextcost2()
 {
   var v_item2 = parseFloat(document.getElementById("InsertRecordITEMUNITS2").value);
if (isNaN(v_item2)) v_item2  = 0;
   var v_cost2  = parseFloat(document.getElementById("InsertRecordITEMCOST2").value);
if (isNaN(v_cost2)) v_cost2  = 0;
    var v_extcost2 = v_item2 * v_cost2;
   document.getElementById("InsertRecordITEMEXTCOST2").value = v_extcost2;

 }

 /* On submitting the webform, the function calculate is executed */
 document.getElementById("caspioform").onchange = calculateextcost2;
 document.getElementById("caspioform").onchange = calculateextcost1;
</SCRIPT>

 

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...