Create Radio Button Group - PHP
In here you can crate a radio button group dynamically.
<?php
$i=0;
foreach ($this->approverList as $key => $category) {
if($i==0){
echo("<input type='radio' . name='Group' value='" . $category->ID . "' checked>" . $category->FULL_NAME . " <br>");
}else{
echo("<input type='radio' name='Group' value='" . $category->ID . "'>" . $category->FULL_NAME . " <br>");
}
$i++;
}
?>
In order to set the Checked value dynamically .Use the following method.
<input disabled type="radio" name="carrytype" value="EMPLOYEE" <?php echo ([DBValue From Object]=='EMPLOYEE' ? 'checked' : '');?> > Employee
I have used the Array List Object which has the ID and FULL_NAME columan.
<?php
$i=0;
foreach ($this->approverList as $key => $category) {
if($i==0){
echo("<input type='radio' . name='Group' value='" . $category->ID . "' checked>" . $category->FULL_NAME . " <br>");
}else{
echo("<input type='radio' name='Group' value='" . $category->ID . "'>" . $category->FULL_NAME . " <br>");
}
$i++;
}
?>
In order to set the Checked value dynamically .Use the following method.
<input disabled type="radio" name="carrytype" value="EMPLOYEE" <?php echo ([DBValue From Object]=='EMPLOYEE' ? 'checked' : '');?> > Employee
Comments
Post a Comment