Reputation: 51
i have a radio button in my form
<input type="radio" id="radio-2" name="radio" checked onclick="calculate()" >
how to set the radio button value based on database value like
if(db_val==2){
value=50
} else{
value=100
}
Upvotes: 1
Views: 583
Reputation: 2835
Radio button value is depend on checked attribute
If you set the checked attribute with condition then its value will be set
Example:
<input type="radio" id="radio-2" name="radio" value="50" <?php echo ($db_val==2)?'checked':'' ?> onclick="calculate()" >
<input type="radio" id="radio-2" name="radio" value="100" <?php echo ($db_val!=2)?'checked':'' ?> onclick="calculate()" >
Upvotes: 2