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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T09:12:29+00:00 2026-06-08T09:12:29+00:00

I have a checkbox next to an input text box. If the checkbox is

  • 0

I have a checkbox next to an input text box. If the checkbox is checked the text box is emptied and disabled. However, I would like to store the value previously in that text box so it will be returned to the text box if the user decides to uncheck the checkbox. Here is my code:

function disablePath() {
    var currentPath;
    $('#user_strategy').on('change','input[value="all"]', function(){
        var that = $(this);
        if($(this).is(':checked')) {
            currentPath = that.next().val();
            that.next().attr("disabled", "disabled").val('');
        }
        else {
            that.next().removeAttr("disabled").val(currentPath);
        }
    });
}

So that works perfectly fine if I only have one checkbox followed by a text box. I run into trouble if I have more than one checkbox-textbox combination, which I do. If I check more than one checkbox, only the last textbox contents is stored – so if I uncheck any of the previously checked boxes then corresponding textbox will get populated with the value of the last textbox whos related checkbox got checked, regardless of relation. Is there a way to store the value of the textbox specific to the previous checkbox? Here is the live code:

http://kaboukie.net/stackoverflow/

I believe I need to use eventData but am uncertain how, any assistance would be greatly appreciated!

  • 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-06-08T09:12:31+00:00Added an answer on June 8, 2026 at 9:12 am

    I would recommend attaching data to the element itself which can be done using Jquery’s .data() method.

    Here is the code, that I have already tested to work properly 😉

    $(function() {
        function disablePath() {
            var currentPath;
            $('#user_strategy').on('change','input[value="all"]', function(){
                var that = $(this);
                if($(this).is(':checked')) {
                    temp= that.next().val();
                    that.data("currentPath" , temp);
                    that.next().attr("disabled", "disabled").val('');
                }
                else {
                    that.next().removeAttr("disabled").val(that.data("currentPath"));
                }
            });
        }
        disablePath();
    }); 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a checkbox which in some cases may be disabled and checked using
I have a text area form like this one: <input id=sg_0 name=sjalfgefid type=text class=letur
I have a HTML snippet like the following <tr class=new> <td> <input name=id type=checkbox/>
I have this code: <input type=checkbox id=checkbox value=11> <input type=checkbox id=checkbox value=10> <div id=log></div>
I have a large form that consists of all the input (text, checkbox, radio,
I have next code, <form id=form1 runat=server> <asp:Label runat=server ID=Label1 EnableViewState=false /> <asp:CheckBox runat=server
I have checkBox and Spinner . If the checkbox is checked, then spinner should
I just want to have php determines whether a checkbox is checked, but I
I have a checkbox for creating a user <input type=checkbox id=chkCreateNewUser name=chkCreateNewUser/><label for=chkCreateNewUser>Create New
I'm currently working on something to check a box and change the text next

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.