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

  • SEARCH
  • Home
  • 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 6933969
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T11:54:02+00:00 2026-05-27T11:54:02+00:00

How could I write this in javascript or jQuery: When I push the button

  • 0

How could I write this in javascript or jQuery:
When I push the button the first time the onoff var in the change function gets the value off and the off button changes to a button named on;
now when I press the on button the var onoff gets the value on and the button changes to an off button again.

<!DOCTYPE HTML>
<html>
<head>
<meta charset="UTF-8">
<script type="text/javascript" src="jquery-min.js"></script>
<script type="text/javascript">
    function change( inputId ) { 
        /* ... do something with inputId ... */
        var onoff = 'off';
        console.log( onoff );
    }
</script>
</head>
<body>
<form>
    <table>
        <tr>
            <td>one:</td><td><input name="one" id="one" /></td>
            <td><input type="button" id="b_one" value="off" onclick="change('one')"></td>
        </tr>
        <tr>
            <td>two:</td><td><input name="two" id="two" /></td>
            <td><input type="button" id="b_two" value="off" onclick="change('two')"></td>
        </tr>
    </table>
    <br /><br /><input type="submit" value="ok"/></div><br />
</form>
</body>
</html>
  • 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-27T11:54:02+00:00Added an answer on May 27, 2026 at 11:54 am

    This is in “pure” JavaScript. You will retrieve the button elements for given input and change its value based on the previous value.

    function change( inputId ) { 
        var button = document.getElementById('b_' + inputId);
        button.value = button.value === 'off' ? 'on' : 'off';
    }
    

    HERE is the code.

    Your change() function won’t work because ‘off’ is assigned to onoff variable everytime the function is called. You have to move the variable definition outside the change() function if you want to use it.

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

Sidebar

Related Questions

Sure I could write this myself, but before I go reinventing the wheel is
I could probably write this myself, but the specific way I'm trying to accomplish
Probably really easy for a pro, but could someone re-write this from it's PHP
I could write myself a helper class that does this when given a functor,
I was hoping someone could give me a hand on how I write this
when releasing an instance that could exist or not, I usually write this: if
How could I write javascript that iterates through a table, grabs the class, and
We want to write a UI that consists of HTML, Javascript (JQuery) and CSS.
I'm learning Javascript (mainly using JQuery) and was wondering if somebody could help me.
I know I could write scripts and create jobs to run them, but at

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.