Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6586213
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T16:45:46+00:00 2026-05-25T16:45:46+00:00

Sorry for a this newbie question, so please be patient with me ;) I

  • 0

Sorry for a this newbie question, so please be patient with me 😉 I am still studying JavaScript/jQuery.

My goal is to ensure that the user will click the image button only once (to avoid having duplicate values due to duplicate form submit).

Here’s the approach that I’m going to do:

Since the button is an image, I could not just disable it after first button click. I could hide the image button but I don’t think that’s a good idea because the user might wonder what happened to the button. So I thought I could just create a global variable in JavaScript to keep track how many times the user clicked the button across duplicate browser tabs.

Here’s my sample code:

HTML

<html>
     <head><title>Global Variable Test 1</title></head>
     <body>
           <script type="text/javascript" src="clickCount.js"></script>
           <a href="#" onClick="countClicks();"><img src="arrow.gif" /></a>
     </body>
</html>

JavaScript

<!-- hide script from old browsers
  var counter = 0;
  function countClicks() {
        counter++;
        if(counter > 1)
       alert("Waah, stop clicking!");
        else
       alert('Number of clicks:' + counter);
  }
// end hiding script from old browsers -->

Well, I was able to count the number of clicks on one page but if I have two tabs open both on the same page, I can’t seem to “share” my variable on the next page (i.e When I click the image button on tab one and click it again in tab two, the click count should be 2 not one). So my question is: How could I create a global variable in JavaScript that could be shared across browser tabs? Is there a better way to ensure that users can only click the image button once?

Any help would be very much appreciated.

TIA.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T16:45:46+00:00Added an answer on May 25, 2026 at 4:45 pm

    My goal is to ensure that the user will click the image button only once (to avoid having duplicate values due to duplicate form submit).

    use the following statement:

        $('#mybuttonid').one("click", function() {
          //my action on click here
        });
    

    it will fires the click event only once

    How could I create a global variable in JavaScript that could be shared across browser tabs?

    You can’t. You can use cookies instead.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Sorry if this is a newbie question. I have a VB.NET subroutine that is
Sorry for this newbie question, but I can't find on google what I need
Sorry if this is a newbie question, searching google and SO turns up nothing,
I'm really new to VSTO so sorry if this is a newbie question. I'm
Sorry fot his newbie question. But I really need a start on this one.
Sorry about this newbie question. Is there a way to execute multiple sentences at
I'm starting with developing, sorry about this newbie question. I need to create a
First : Appologize for my bad english. Sorry for this newbie software question, but
Sorry if this is a newbie question. I can't seem to find a response
Sorry if this is a newbie question, I'm a bit rusty in Access and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.