Solved

Help with jquery to change value in textbox control

Posted on 2014-12-08
4
144 Views
Last Modified: 2014-12-08
I have  a checkbox called cboFee and a textbox called txtAmount.   When someone clicks on the checkbox I need to add $20.00 to the amount field.  if the checkbox is unchecked I need to subtract from it.  This needs to be done in jquery because I don't want to do  a call back.   Could someone give me sample code and how this would work.

thanks
0
Comment
Question by:mgmhicks
  • 2
  • 2
4 Comments
 
LVL 58

Expert Comment

by:Gary
Comment Utility
$("#checkboxid").change(function(){
    if($(this).is(":checked")){
        $("#textboxid").val(parseFloat($("#textboxid").val()+20))
    }
    else{
        $("#textboxid").val(parseFloat($("#textboxid").val()-20))
    }
})

Open in new window

0
 

Author Comment

by:mgmhicks
Comment Utility
this is what I have because of master page

$("#<%=cbxfee.ClientID  %>").change(function() {
    if ($(this).is(":checked")) {
        $("#<%=txtAmt.ClientID %>").val(parseFloat($("#<%=txtAmt.ClientID %>").val() + 20))
    }
    else {
        $("#<%=txtAmt.ClientID %>").val(parseFloat($("#<%=txtAmt.ClientID %>").val() - 20))
    }
})
                  
            });
seems like when it adds it appends the value put when it subtracts it does subtract it. I start off with 0.00 , check the box and I get 0.002 then I click it again I get, -19.998

so we are close
thanks
0
 
LVL 58

Accepted Solution

by:
Gary earned 500 total points
Comment Utility
Had the brackets in the wrong place

$("#<%=cbxfee.ClientID  %>").change(function() {
     if ($(this).is(":checked")) {
         $("#<%=txtAmt.ClientID %>").val(parseFloat($("#<%=txtAmt.ClientID %>").val()) + 20)
     }
     else {
         $("#<%=txtAmt.ClientID %>").val(parseFloat($("#<%=txtAmt.ClientID %>").val()) - 20)
     }
 })
                   
             });

Open in new window

0
 

Author Closing Comment

by:mgmhicks
Comment Utility
thank you
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now