1
 <?php $result2 = db_getsub( array('campaigns_id' => $SYS_campaign) );
                            if (!is_null($result1)){ 

                                while ( $row = $result2->fetch_object() )
                                {


                            ?>
                    <div class="item">
                        <div style="text-align: left;">
                            <div class="choicetitle">
                                 <input type="radio" id="Radio1" checked="checked" title="" name="subtype"  value="<?php echo   $row->subid;  ?>" /><?php echo  $row->sub_name;  ?></div>
                            <div class="choicedesc descrip">
                                <?php echo $row->gavdescrep;  ?> </div>
                           <!-- <div class="choicelesmer">
                                Les mer
                            </div>-->
                            <div class="choicedesc1">
                                <?php echo $row->gavdescrep; ?> </div>
                        </div>
                        <span><?php 

                         $value=$row->price;
                        if($value != 0)
                        { 
                        echo $row->price; ?>,-

                       <?php }else { echo ""; } ?> </span>
                        <span class="bgcolor discprice">
                        <?php echo $row->pricediscount; ?>,-
                        </span>
                    </div>
                    <?php  } } ?>

I want to show default 1st radio button checked now its showing last button checked as it is coming dynamically any help???

Renjith
  • 5,783
  • 9
  • 31
  • 42

3 Answers3

1

You are using checked="checked" for all your radio buttons in the loop. So, last assigned radio button retains the checked property. To solve the problem, Conditionally set checked="checked" only for the first looping

    if(loopingFirstTime){
        $checked = ' checked="checked" ';
    }else{
        $checked = ' ';
    }

and then ....

    <input type="radio" name="radio1" '.$checked.' />

Not tested this .... please check the syntax

rags
  • 2,580
  • 19
  • 37
0

Use checked=checked property to make a radio button checked by default:-

Blue

http://www.w3schools.com/jsref/prop_radio_defaultchecked.asp

And to handle that with jquery:-

jQuery("#radio_1").attr('checked', 'checked');

How to check a radio button with jQuery ?

Community
  • 1
  • 1
abhinsit
  • 3,214
  • 4
  • 21
  • 26
0

Like the other guys have already said, you have only implemented one radio button. You can try jsfiddle.net for example to try out you code and quickly see your changes.

Btw: I'm not quite sure what you're trying to do in you last row: Is that a leftover or those this belong to the wrapped-around code?

Beejay
  • 183
  • 1
  • 3
  • 13