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 6980477
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T18:01:25+00:00 2026-05-27T18:01:25+00:00

I am calling a function onclick secVar(sec1); which should run it through the script

  • 0

I am calling a function onclick secVar(sec1); which should run it through the script below, but it does not seem to be doing so, can someone tell me what I am doing incorrectly. I am new to javascript, and only have a little experience into scripting, and this code seems to be doing less and less of what I want it to.

<script type="text/javascript">
        var sec1=0;
        var sec2=0;
        var sec3=0;
        function secVar(){
            if(sec1) {
                sec1++;
                document.getElementById('sec1text').innerHTML = sec1;
            }
            if(sec2) {
                sec2++;
                document.getElementById('sec2text').innerHTML = sec2;
            }
            if(sec3) {
                sec3++;
                document.getElementById('sec3text').innerHTML = sec3;
            }
        }

        function largestVar(){
                if (sec1 >= sec2 && sec1 >= sec3) {
                    //a
                    document.getElementById('rig').innerHTML = 'Test1';
                } else if (sec2 >= sec1 && sec2 >= sec3) {
                    //b
                    document.getElementById('rig').innerHTML = 'Test2';
                } else {
                    //c
                    document.getElementById('rig').innerHTML = 'Test3';
                }
            }
    </script>

If this helps, The old code was the code below, before I tried to add in the script to determine the largest of the variables. It was incrementing the variables onclick, but no longer so. The onclick contained sec1Var() at that point.

<script type="text/javascript">
    var sec1=0;
    var sec2=0;
    var sec3=0;

    function sec1Var(){
    sec1++;
    document.getElementById('sec1text').innerHTML = sec1;
    }

    function sec2Var(){
    sec2++;
    document.getElementById('sec2text').innerHTML = sec2;
    }

    function sec3Var(){
    sec3++;
    document.getElementById('sec3text').innerHTML = sec3;
    }</script>

If someone can explain to me what I am doing wrong I would greatly appreciate it.

  • 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-27T18:01:26+00:00Added an answer on May 27, 2026 at 6:01 pm

    I think it’s hard to tell what your intention is. Sparticus has it right IF what you’re trying to do is see if sec1, 2, and 3 are currently true or false (0 or 1). Since they are currently false, the code will never do anything as Sparticus correctly points out.

    However, I’m not convinced that’s actually what you MEAN to do. It looks like the condition you want to check is whether or not you’re trying to increment sec1, 2, or 3. In other words, “If you are passing me sec1, increment it and update a piece of HTML”.

    But variables don’t work that way. When you say secVar(sec1) what you are actually saying is `secVar(0)’. I don’t think that’s your intention.

    So, a big waste of my time if I’m wrong, but because I’m already rolling along, let’s pretend I’m right:

    secVar needs to be able to accept a parameter, but right now you’ve declared it void. Changing it to accept a parameter is a first step:

    function secVar(param) { ... };

    But this still won’t do anything. Because when you’re still passing it “0” with your existing syntax. You need to pass it something that can be checked, like a string:

    secVar('sec1');

    When you do this, you can now update your conditions to check which string is being passed

    if (param === 'sec1') { ... }

    Here’s a fiddle: http://jsfiddle.net/ch4yk/

    Notes:

    • The fiddle includes jQuery just for easy brute-force event binding on the buttons. It’s just an example. You don’t need jQuery; bind your events however you want.
    • It is currently not doing anything with the largest value function, even though the code is in the fiddle
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm calling the first function below to bind the second function to the onClick
I'm trying to return a value from (transport) to the calling function, but can't
Does anyone know how to watch a variable in calling function. For example: C#:
So I have a TimerTask task calling a function onTimerComplete() in its run() onTimerComplete()
I have an onclick function which performs several tasks. In another JavaScript function I
I'm calling a javascript function in an inline onclick like so: <a href=# onclick=removeAttribute('foo',
calling a js function using onclick... onclick=SubmitAge(66, 'ctl00_MainContent_arTo_upAgeRange') function just calls an updatePanel from
What's the difference using addEventListner and simply Onclick/Ondblclick calling a function(s)?
I am calling two function one Java script and one Jquery function on click
I have a javascript function that I am calling from an image onClick event

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.