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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T23:06:58+00:00 2026-05-29T23:06:58+00:00

My problem is simple not so lengthy as looking like. I have 7 textboxes

  • 0

My problem is simple not so lengthy as looking like.

I have 7 textboxes having ids text1, text2, text3, text4 and text5, text6, text7 and one checkbox having id check. I am getting value of text1 and text2 by JSON as 10 and 20 and displaing total 30 in text7. Values of text4,text5 and text6 are empty that is these textboxes display “0”. text3 and text4 will be autofilled based on checkbox.

When i checked the checkbox then “Points” will be autofilled in text3 and “100” will be autofilled in text4. Now total text7 will show 130. Values of text5 and text6 display “0”. If i will write something let’s say “10” in text5 and “20” in text6 then total text7 will show 160. If i uncheck the checkbox, then values of text3 and text4 will be removed and total will be changed acordingly.I am not able to know how to autofill text3 and text4 after checking the checkbox, any idea please?

index.jsp

 $(document).ready(function() {
 $("#combo1").change(function() {
 $.getJSON(
    'combo1.jsp', 
    { combo1Val : $(this).val() }, 
    function(data) {
        var a = data.valueoffirsttextbox; //Got 10 from db
        var b = data.valueofsecondtextbox; //Got 20 from db
        var total = parseInt(a) + parseInt(b);
 $("#combo2").val(data.name);
        $("#text1").val(a)
        $("#text2").val(b)
        $("#text7").val(total); // here i am showing total 30 in text7  
    }
  );
// when checkbox is unchecked text4 is not present 
       $("#text1, #text2, #text5, #text6").keyup(function() {// if any editing occurs
 in these values then total will be changed accordingly
 var a = $("#text1").val();
 var b = $("#text2").val();
 var c = $("#text5").val();
 var d = $("#text6").val();
 var total = parseInt(a) + parseInt(b) + parseInt(c) + parseInt(d);
 $("#text7").val(total);// shows total with out text4's value

// when checkbox is checked then text4's value is added

       $("#text1, #text2, #text4, #text5, #text6").keyup(function() {// if any editing
  occurs in these values then total will be changed accordingly
 var a = $("#text1").val();
 var b = $("#text2").val();
 var c = $("#text5").val();
 var d = $("#text6").val();
//here text4 is added
 var e = $("#text4").val();
 var total = parseInt(a) + parseInt(b) + parseInt(c) + parseInt(d) + parseInt(e) ;
 $("#text7").val(total);// show total with text4's value
 });
 });
 });   

<body>
<input type="checkbox" id=check"/>

<input type="text" id="text1"/>
<input type="text" id="text2"/>
<input type="text" id="text3"/>// how can i autofill "POINTS" in this 
textbox after checking the checkbox?
<input type="text" id="text4" value="0"/>//how can i autofill "100" in this textbox 
after checking the checkbox?
<input type="text" id="text5" value="0"/>
<input type="text" id="text6" value="0"/>
<input type="text" id="text7" value="0"/>// shows total of all values of above  
textboxes except text3
</body>
  • 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-29T23:06:59+00:00Added an answer on May 29, 2026 at 11:06 pm

    You can check this jsFiddle: http://jsfiddle.net/Af6LP/1/ Modify it according to your needs.

    Script

    $(document).ready(function() {
      $("#check").change(function() {
          if ($(this).is(":checked")) $("#text4").val("100");
          else $("#text4").val("0");
          calculate();
      });
    
      $("#text1, #text2, #text5, #text6").keyup(function() {
          calculate();
      });
    });
    
    function calculate() {
      var a = $("#text1").val();
      var b = $("#text2").val();
      var c = $("#text5").val();
      var d = $("#text6").val();
      var total = parseInt(a) + parseInt(b) + parseInt(c) + parseInt(d);
      if ($("#check").is(":checked")) total += parseInt($("#text4").val());
      $("#text7").val(total);
    }​
    

    HTML

    <body>
        <input type="checkbox" id="check"/><br/>
        <input type="text" id="text1" value="10"/><br/>
        <input type="text" id="text2" value="20"/><br/>
        // how can i autofill "POINTS" in this textbox after checking the checkbox?
        <input type="text" id="text3"/><br/>
        //how can i autofill "100" in this textbox after checking the checkbox?
        <input type="text" id="text4" value="0"/><br/>
        <input type="text" id="text5" value="0"/><br/>
        <input type="text" id="text6" value="0"/><br/>
        // shows total of all values of above textboxes except text3<br/>
        <input type="text" id="text7" value="30"/>
    </body>​
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple problem but I am not sure how to solve it.
This problem is not readily reproducible in a simple example here but was wondering
My problem seems to be quite simple, but it's not working the intuitive way.
simple problem with a simple question. I have a string, in C# i can
I have what I though was a simple problem to solve (never is!) I'm
I have what I hope to be a pretty simple problem. I'm very simply
Referring on this question , I have a similar -but not the same- problem..
my problem seems simple but I can not manage to find an answer here.
I have - I think - a very simple problem I want to align
I'm currently looking at a simple programming problem that might be fun to optimize

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.