Link to home
Start Free TrialLog in
Avatar of mgmhicks
mgmhicks

asked on

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
Avatar of Gary
Gary
Flag of Ireland image

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

Open in new window

Avatar of mgmhicks
mgmhicks

ASKER

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
ASKER CERTIFIED SOLUTION
Avatar of Gary
Gary
Flag of Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
thank you