Jump to content

Custom script only works when website is refreshed not on first load.

Recommended Posts

Site URL: http://www.hausline.be/contact

I have a problem where the script that changes the default values of the contact form (first name and last name) are changed to my language, but it is only executed when I refresh the page. On first load the scripts doesn't change anything. 

This is the code I used, after some extensive searching here on the forums.

function addLoadEvent(func) {
 var oldonload = window.onload;
 if (typeof window.onload != 'function') {
   window.onload = func;
 } else {
   window.onload = function() {
     if (oldonload) {
addLoadEvent(function() {  
 sqsFirstName = document.getElementsByClassName("caption")[0].innerHTML;
 myFirstName = sqsFirstName.replace("First Name", "Voornaam");
 document.getElementsByClassName("caption")[0].innerHTML = myFirstName;

 sqsLastName = document.getElementsByClassName("caption")[1].innerHTML;
 myLastName = sqsLastName.replace("Last Name", "Naam");
 document.getElementsByClassName("caption")[1].innerHTML = myLastName;


Anyone know where I went wrong? Thanks.

Link to comment
  • Replies 2
  • Created
  • Last Reply


This topic is now archived and is closed to further replies.

  • Create New...

Squarespace Webinars

Free online sessions where you’ll learn the basics and refine your Squarespace skills.

Hire a Designer

Stand out online with the help of an experienced designer or developer.