Welcome Guest, Not a member yet? Register   Sign In
form_vaidation: dynamic Default-value for radio, select, checkbox?
#1

[eluser]Unknown[/eluser]
Hello,

is there a way to dynamically set the default-Value for radio-buttons?

According to the documentation you can set the default-Value for a radio-button like this:

Code:
<input type="radio" name="myradio" value="1" <?php echo set_radio('myradio', '1', TRUE); ?> />
<input type="radio" name="myradio" value="2" <?php echo set_radio('myradio', '2'); ?> />

In my case I read a value from a database and want to activate the according value (1 or 2) in the radio-button. Is there something like

Code:
<input type="radio" name="myradio" value="1" <?php echo set_radio('myradio', '1', $default_1); ?> />
<input type="radio" name="myradio" value="2" <?php echo set_radio('myradio', '2', $default_2); ?> />
#2

[eluser]darkhouse[/eluser]
Try this:

Code:
<input type="radio" name="myradio" value="1" <?php echo set_radio('myradio', '1', ($value_from_db == 1)); ?> />
<input type="radio" name="myradio" value="2" <?php echo set_radio('myradio', '2', ($value_from_db == 2)); ?> />




Theme © iAndrew 2016 - Forum software by © MyBB