Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

132
Views
Add a count to simple JS to stop it repeating

I'm trying to add a simple count to the below JavaScript in the hope it will only be performed once, ideally even on page refresh, but the form could be reloaded with ajax:

jQuery(document).on('gform_post_render', function () {
    if (jQuery("#input_51_1").val().length > 0) {
        jQuery('form#gform_51').trigger('submit');
    } else {
        // Do nothing
    }
});
almost 4 years ago · Santiago Trujillo
1 answers
Answer question

0

You can use localStorage as a flag variable

First check if item in localStorage is setted with getItem, and if is not set it using setItem

jQuery(document).on('gform_post_render', function () {
    if (!localStorage.getItem('gform_post_renderEventTriggered')) {
        localStorage.setItem('gform_post_renderEventTriggered', true);
        if (jQuery("#input_51_1").val().length > 0) {
            jQuery('form#gform_51').trigger('submit');
        } else {
            // Do nothing
        }
    }
});
almost 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!