I have a select box in my form and when I hit submit the form goes through validation and if an error happens, return all the value. This work expect for my select box, I have use the set_select but it doesnt work data comes in data base
<select name="leave_category_id" class="form-control" onchange="check_leave_category(this.value)" required >
<option value="" >Select Leave Category...</option>
<?php foreach ($all_leave_category as $v_category) :
?>
<option value="<?php echo $v_category->leave_category_id ?>" >
<?php echo set_select('leave_category_id',$cat); ?>
<?php echo $v_category->category ?> </option>
<?php endforeach;
?>
</select>
The set_select()
function prints out the selected="selected"
attribute in the <option>
element where appropriate. But your code is as follows:
<option value="<?php echo $v_category->leave_category_id ?>" >
^
closing the tag --> |
<?php echo set_select('leave_category_id',$cat); ?>
<?php echo $v_category->category ?>
</option>
So when you look at the html, it will look something like this:
<option value="123">selected="selected" Category Name</option>
Got it? Your selected
attribute is placed outside the tag. I guess you'll be able to fix it now ;)