开发者

How can I make the text adjacent to my checkbox clickable in php

how can I make users check on textclick? My script is: 开发者_JAVA技巧

 <?php 
      foreach($getcountry_name as $key => $value)
 { ?>
    <tr>
        <td width="25" valign="top">
        <input name="country_name[]"  
             type="checkbox" checked="checked" 
             value="<?php echo $value['country_id']; ?>" />
        </td>
        <td>
        <label class="type01"><?php echo $value['country_name']; ?></label>
        </td>
    </tr> 
   <?php
     }
   ?>        

thanks in advance


The <label> needs a for attribute that contains the ID of the <input> field it's linked to.

e.g.

<input id="myID" name="country_name[]"  type="checkbox" checked="checked" value="<?php echo $value['country_id']; ?>" />
<label for="myID" class="type01"><?php echo $value['country_name']; ?></label>

Edit:

Applying it to your example,

<?php 
      foreach($getcountry_name as $key => $value)
 { ?>
    <tr>
        <td width="25" valign="top">
        <input id="country_name_<?php echo $value['country_id']; ?>" name="country_name[]"  
             type="checkbox" checked="checked" 
             value="<?php echo $value['country_id']; ?>" />
        </td>
        <td>
        <label for="country_name_<?php echo $value['country_id']; ?>" class="type01"><?php echo $value['country_name']; ?></label>
        </td>
    </tr> 
   <?php
     }
   ?>  


Give the inputan ID and let your label use this as the value for a for attribute.


<tr>
    <td width="25" valign="top">
        <input id="<?php $id=uniqid('id_'); echo $id; ?>" name="country_name[]" type="checkbox" checked="checked" value="<?php echo $value['country_id']; ?>" />
    </td>
    <td>
        <label for="<?php echo $id; ?>" class="type01"><?php echo $value['country_name']; ?></label>
    </td>
</tr>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜