Jump to content

Help with converting .onsubmit to .addEventListener


Recommended Posts

Hello,

I had a JavaScript that concatenated fields together to make headings on a chart. The script used the .onsubmit command and worked fine up until disable AJAX was deleted. I understand that .onsubmit was replaces with document.addEventListener, however I haven't found any adequate documentation on how to make the implementation. All the JS samples provided in the tutorial section haven't been updated and from scrolling through the forum, I haven't had any luck either.

<SCRIPT LANGUAGE="JavaScript">

document.addEventListner("DataPageReady",concatenate1);

function concatenate1()
{
var SchedStatus = document.getElementById("InsertRecordStatus").value;
var Control = document.getElementsByName("InsertRecordID")[0].value;
var Company = document.getElementById("InsertRecordCompany").value;
var Company25 = Company.substring(0,25);
var Position = document.getElementsByName("InsertRecordPosition")[0].value;
var Date = document.getElementById("InsertRecordDate_Open").value;
var Product = document.getElementById("InsertRecordProduct").value;
var Product = Product.replace("cors","");
var Product = Product.replace("ersity","");
var Product7 = Product.substring(0,7);
var ControlType = document.getElementById("InsertRecordControl_Type").value;
var FU = "";
var FUC = "";
var FUY = "";
var FUV = "";
var FUContacts = document.getElementById("InsertRecordFollowUp_ContactsNeeded").value;
var FUYes = document.getElementById("InsertRecordFollowUp_YesNeeded").value;
var FUViable = document.getElementById("InsertRecordFollowUp_ViableNeeded").value;


var CompanyPosition = Control + ' - ' + Company + ' (' + Position + ')';

document.getElementById("InsertRecordCompany_Position").value = CompanyPosition;

if (ControlType != "Regular")
{
if (FUContacts)
   var FUC = FUContacts + 'C';
if (FUYes)
   var FUY = FUYes + 'Y';
if (FUViable) 
   var FUV = FUViable + 'V';

var FU = FUC + FUY + FUV;
}

if (ControlType != "Regular" && SchedStatus == "Future Credit")
   var DateControl = 'FCF - ' + Date + ' - ' + Control + ' (' + FU + ')' + ' - ' + Company25 + ' (' + Product7 + ')';

if (ControlType != "Regular" && SchedStatus == "Open")
   var DateControl = Date + ' - ' + Control + ' (' + FU + ')' + ' - ' + Company25 + ' (' + Product7 + ')';

if (ControlType == "Regular" && SchedStatus == "Future Credit")
   var DateControl = 'FCR - ' + Date + ' - ' + Control + ' - ' + Company25 + ' (' + Product7 + ')';

if (ControlType == "Regular" && SchedStatus == "Open")
   var DateControl = Date + ' - ' + Control +  ' - ' + Company25 + ' (' + Product7 + ')';


document.getElementById("InsertRecordDate_Control").value = DateControl;

}


//Old onsubmit function no longer supported
//document.getElementById("caspioform").onsubmit=concatenate1;

</SCRIPT>

 

This code is in the footer. As I said, it worked fine before the deprecation so I'm assuming I just don't get the addEventHandler line. Any help would be appreciated.

Thanks,

Bill

Link to comment
Share on other sites

"DataPageReady" event listener runs when the page is fully loaded. I'm guessing this is where your problem is, because your submission form fields won't have any values by the time the event listener runs. 

Try This will run your concactenate1 function when the user submits the page. When the submit button is clicked, it will run the function and then submit.

document.addEventListener('BeforeFormSubmit', concatenate1);

This will run your concactenate1 function when the user submits the page. When the submit button is clicked, it will run the function and then submit.

Link to comment
Share on other sites

On 12/20/2023 at 2:09 PM, kpcollier said:

"DataPageReady" event listener runs when the page is fully loaded. I'm guessing this is where your problem is, because your submission form fields won't have any values by the time the event listener runs. 

Try This will run your concactenate1 function when the user submits the page. When the submit button is clicked, it will run the function and then submit.

document.addEventListener('BeforeFormSubmit', concatenate1);

This will run your concactenate1 function when the user submits the page. When the submit button is clicked, it will run the function and then submit.

 

Thank you so much, that was it. I really appreciate your help.

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