Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 187
  • Last Modified:

Help with jquery to change value in textbox control

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
mgmhicks
Asked:
mgmhicks
  • 2
  • 2
1 Solution
 
GaryCommented:
$("#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
 
mgmhicksAuthor Commented:
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
 
GaryCommented:
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
 
mgmhicksAuthor Commented:
thank you
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now