Page 1 of 1

dynamic options

Posted: Fri Jan 28, 2011 4:00 am
by aravona
I've a series of options (chosen with a radio button) which draw data from my database, I want to make the first option automatically chosen.

Right now I can only get it to auto-choose the last option.

The problem I'm having is there is no set value as it chooses it from the DB and theres a number of options that this could be so I don't know how to go about forcing it to the first one.

Code: Select all

<?php while (wpsc_have_variation_groups()) : wpsc_the_variation_group(); ?>
<input type="radio"  value="<?php echo wpsc_the_variation_id(); ?>" class='wpsc_select_variation' name="variation[<?php echo wpsc_vargrp_id(); ?>]" id="<?php echo wpsc_vargrp_form_id(); ?>" checked="checked">
<?php endwhile; ?>
The above code is what generates the radio buttons, any ideas how to make this choose the first option?

Cheers,

Aravona

Re: dynamic options

Posted: Fri Jan 28, 2011 5:57 am
by maneetpuri
Hi,

Define a variable set to zero and in the loop check if the value is zero then add the checked attribute and make the value of this variable 1 and this will make the first radio button selected by default.

Cheers,

~Maneet