PHP select radio and checkbox by default

  • 2020-03-31 20:45:29
  • OfStack

This is the implementation method that extends yibing's select default selection
 
<select name="wuyeleixing" size="1"> 
<option <?php if($myrow[wuyeleixing]==1) echo("selected");?> value="1"> residential </option> 
<option <?php if($myrow[wuyeleixing]==2) echo("selected");?> value="2"> The office </option> 
<option <?php if($myrow[wuyeleixing]==3) echo("selected");?> value="3"> YingYeFang </option> 
<option <?php if($myrow[wuyeleixing]==4) echo("selected");?> value="4"> workshop </option> 
<option <?php if($myrow[wuyeleixing]==5) echo("selected");?> value="5"> warehouse </option> 
<option <?php if($myrow[wuyeleixing]==6) echo("selected");?> value="6"> plot </option> 
<option <?php if($myrow[wuyeleixing]==7) echo("selected");?> value="7"> Complex building </option> 
<option <?php if($myrow[wuyeleixing]==8) echo("selected");?> value="8"> Cattle ranches </option> 

<option <?php if($myrow[wuyeleixing]==9) echo("selected");?> value="9"> mass </option> 
<option <?php if($myrow[wuyeleixing]==10) echo("selected");?> value="10"> The hotel restaurant </option> 
<option <?php if($myrow[wuyeleixing]==11) echo("selected");?> value="11"> School buildings </option> 

</select> 

Default selection implementation of the radio menu
 
<input type="radio" name="dishu" value="3" <?php if($myrow[dishu]==3) echo("checked");?>> blank  
<input type="radio" name="dishu" value="1" <?php if($myrow[dishu]==1) echo("checked");?>> transfer  
<input type="radio" name="dishu" value="2" <?php if($myrow[dishu]==2) echo("checked");?>> transfer  
<input type="radio" name="dishu" value="4" <?php if($myrow[dishu]==4) echo("checked");?>> The collective  

The default selection implementation of the checkbox checkbox
 
<input name="fujia_jiaju" type="checkbox" value="jiaju" <?php if($myrow[fujia_jiaju]) echo("checked");?>></font></strong> furniture </td> 
<td width="108" height="1"><strong><font color="#008080" face=" Regular script _GB2312"><input 
name="fujia_chuju" type="checkbox" value="chuju" <?php if($myrow[fujia_chuju]) echo("checked");?>></font></strong> Kitchen utensils and appliances </td> 
<td width="96" height="1"><strong><font color="#008080" face=" Regular script _GB2312"><input 
name="fujia_woju" type="checkbox" value="woju" <?php if($myrow[fujia_woju]) echo("checked");?>></font></strong> bedding </td> 
<td width="99" height="1"><strong><font color="#008080" face=" Regular script _GB2312"><input 
name="fujia_TV" type="checkbox" value="TV" <?php if($myrow[fujia_TV]) echo("checked");?>></font></strong> The TV  

These form fields work together to modify some database records and keep them the same as when they were added!

Select is selected by default, and select gets the selected item

Ok, have to admit, I how JS dishes, only can read a few lines of code are sometimes difficult, such as to solve the problems of the front end of the select the default selected today it took me nearly half an hour, finally find the code to solve the select retrieve the selected item is quite simple, and HTML select selected using the JS to solve or very productive, select the chosen this solution I think worth keeping down and share with friends. The code is as follows:

 
<form name="FORM" method="post" action="" enctype="multipart/form-data"> 
<select name='aaa' id='bbb'> 
<option value=''> The existing classification </option><option value=' Inner Mongolia '> Inner Mongolia </option> 
<option value=' xinjiang '> xinjiang </option><option value=' yunnan '> yunnan </option> 
<option value=' Tibet '> Tibet </option><option value=' gansu '> gansu </option> 
<option value=' ningxia '> ningxia </option><option value=' qinghai '> qinghai </option> 
<option value=' sichuan '> sichuan </option><option value=' guangxi '> guangxi </option> 
<option value=' guizhou '> guizhou </option><option value=' hainan '> hainan </option> 
<option value=' guangdong '> guangdong </option><option value=' hunan '> hunan </option> 
<option value=' hubei '> hubei </option><option value=' fujian '> fujian </option> 
<option value=' jiangxi '> jiangxi </option><option value=' zhejiang '> zhejiang </option> 
<option value=' anhui '> anhui </option><option value=' jiangsu '> jiangsu </option> 
<option value=' henan '> henan </option><option value=' shaanxi '> shaanxi </option> 
<option value=' shandong '> shandong </option><option value=' hebei '> hebei </option> 
<option value=' shanxi '> shanxi </option><option value=' heilongjiang '> heilongjiang </option> 
<option value=' Ji Lin '> Ji Lin </option><option value=' liaoning '> liaoning </option> 
</select> 
</form> 
<script type="text/java script"> 
<!-- 
document.FORM.bbb.value = " yunnan ";//FORM is the FORM name, atc_province is the select tag ID,
 Yunnan is select Default selected item  
//--> 
</script> 

I hope it was helpful to you

Related articles: