Subu Hunter
Subu Hunter

Reputation: 63

I want to change the price based on the checkboxs selected

price should change depending on the checkboxes selected. (i.e) 2 set of checkboxes are there they have 3 values each. depending on the values selected the rpice should change which would be in a readonly input

if (document.getElementById("sedan").checked = true && document.getElementById("chtiru").checked = true) { 
    $("#trip_cost").val("2000");   
} else if (document.getElementById("Premiumx").checked = true && document.getElementById("chtiru").checked = true){      
    $("#trip_cost").val("3000");   
} else if (document.getElementById("Force").checked = true && document.getElementById("chtiru").checked = true){      
    $("#trip_cost").val("3050");    
} else {
  $("#price").val("");
}

Upvotes: 1

Views: 72

Answers (1)

cнŝdk
cнŝdk

Reputation: 32145

The problem of your code is that you are using assignement operator = instead of comparison operator == , so the first condition will be always true.

And for boolean values writing if(document.getElementById("Premiumx").checked)is enough you don't need to write == true.

This is how should be your code:

if (document.getElementById("sedan").checked && document.getElementById("chtiru").checked) { 
    $("#trip_cost").val("2000");   
} else if (document.getElementById("Premiumx").checked && document.getElementById("chtiru").checked){      
    $("#trip_cost").val("3000");   
} else if (document.getElementById("Force").checked && document.getElementById("chtiru").checked){      
    $("#trip_cost").val("3050");    
} else {
  $("#price").val("");
}

Upvotes: 1

Related Questions