Jump to content

Using Multiple Javascripts In Submission Forms


Recommended Posts

I have a question about using multiple JavaScripts in a single submission form. I want to use three different JavaScripts in a single form, but as soon as I enter in more than one the other stops working.

 

For example, in my footer I have one to concatenate email address for the acknowledgement email into a virtual field and one to do a date check to make sure one date is greater than today's date, etc.

 

When I enter the date script the concatenation script stops working and vice versa.

 

I have tried moving the date check script to an HTML box but it does not resolve the issue.

 

Any suggestions or assistance would be greatly appreciated. I am not sure what I am doing wrong here.

 

 

I have attached my footer scripts for convenience.

 

 

 

<SCRIPT LANGUAGE="JavaScript">
 
function concatenate()
{
var position1 = document.getElementsByName("InsertRecordStore_Email")[0].value;
//alert("position1 :" + position1 );
//alert("position1+ :" + document.getElementsByName("InsertRecordStore_Email")[0].value);
 
 
var position2 = document.getElementsByName("InsertRecordBiller_Email")[0].value;
//alert("position2 :" + position2 );
//alert("position2+ :" + document.getElementsByName("InsertRecordBiller_Email")[0].value);
 
 
 
var allpositions = position1 + ";" + position2;
 
document.getElementById("cbParamVirtual3").value = allpositions;
}
 
document.getElementById("caspioform").onsubmit=function()
{
concatenate();
}
</SCRIPT>
 
 
 
 
 
<SCRIPT LANGUAGE="JavaScript">
 function checkStart()
{
   var v_sDate = document.getElementById("InsertRecordInStoreSFA_Start").value;
   var v_eDate = document.getElementById("InsertRecordInStoreSFA_End").value;
   var sDate = new Date(v_sDate);
   var eDate = new Date(v_eDate);
   var nDate = new Date();
   nDate = Date.now();
   var setToday = sDate.getDate() + 1;
   sDate.setDate(setToday);
   setToday = eDate.getDate() + 1;
   eDate.setDate(setToday);
   if (sDate<nDate)
      {
         alert("SFA start date must be greater than today");
         return false;
      }
      else
        {
            if (eDate<sDate)
              {
                  alert("SFA end date must be greater than SFA start date");
                  return false;
              }
        }
}   
document.getElementById("caspioform").onsubmit=checkStart;
</SCRIPT>
Link to comment
Share on other sites

Hello Liz,

 

I think, you can try to write the code of both functions in one, like the following code:

 

<SCRIPT LANGUAGE="JavaScript">
function bothFunctions()
{
var position1 = document.getElementsByName("InsertRecordStore_Email")[0].value;
//alert("position1 :" + position1 );
//alert("position1+ :" + document.getElementsByName("InsertRecordStore_Email")[0].value);

var position2 = document.getElementsByName("InsertRecordBiller_Email")[0].value;
//alert("position2 :" + position2 );
//alert("position2+ :" + document.getElementsByName("InsertRecordBiller_Email")[0].value);

var allpositions = position1 + ";" + position2;

document.getElementById("cbParamVirtual3").value = allpositions;

var v_sDate = document.getElementById("InsertRecordInStoreSFA_Start").value;
var v_eDate = document.getElementById("InsertRecordInStoreSFA_End").value;
var sDate = new Date(v_sDate);
var eDate = new Date(v_eDate);
var nDate = new Date();
nDate = Date.now();
var setToday = sDate.getDate() + 1;
sDate.setDate(setToday);
setToday = eDate.getDate() + 1;
eDate.setDate(setToday);
if (sDate<nDate)
      {
         alert("SFA start date must be greater than today");
         return false;
      }
      else
        {
            if (eDate<sDate)
              {
                  alert("SFA end date must be greater than SFA start date");
                  return false;
              }
        }
}   
document.getElementById("caspioform").onsubmit=bothFunctions;
</SCRIPT>

I hope, it helps.

Link to comment
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...