TuffBee TuffBee - 7 months ago 39
SQL Question

Sum of multiple selected checkboxes in JAVA

If I use the "+ " sign it will just concatenate the values, but I need to find the mathematical values. I need to insert the quantity of a product. How to find the sum when multiple checkboxes are selected?
I have tried this which concatenates.. Also the values need to go into the database, it is working with the concatenated values..

if(chckbx1.isSelected()){
qty= chckbx1.getText();
chckbx1.setSelected(true);
}

if(chckbx1.isSelected() && chckbx5.isSelected()){
qty= chckbx1.getText() + chckbx5.getText();
chckbx5.setSelected(true);
chckbx1.setSelected(true);
}

Answer

You need to parse it to Double using Double.parseDouble()

qty= (Double.parseDouble(chckbx1.getText()) + Double.parseDouble(chckbx5.getText())) + "";