Solved

Help with jquery to change value in textbox control

Posted on 2014-12-08
4
168 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 58

Expert Comment

by:Gary
ID: 40487171
$("#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
ID: 40487282
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
ID: 40487290
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
ID: 40487303
thank you
0

Featured Post

Why Off-Site Backups Are The Only Way To Go

You are probably backing up your data—but how and where? Ransomware is on the rise and there are variants that specifically target backups. Read on to discover why off-site is the way to go.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
Introduction JSON is an acronym for JavaScript Object Notation.  It is a text-string data transport mechanism, capable of representing simple or complex data structures in a consistent and easy-to-read manner.  Similar in concept to XML, but more e…
The viewer will learn how to dynamically set the form action using jQuery.
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)

734 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