PHP select,radio and checkbox Default selection implementation method _php tips

Source: Internet
Author: User
This is the implementation method of the Select default selection of the extended yibing
Copy Code code as follows:

<select name= "wuyeleixing" size= "1" >
<option <?php if ($myrow [Wuyeleixing]==1) Echo ("selected");? > value= "1" > Residences </option>
<option <?php if ($myrow [wuyeleixing]==2) Echo ("selected");? > value= "2" > Office </option>
<option <?php if ($myrow [wuyeleixing]==3) Echo ("selected");? > value= "3" > Business room </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" > Comprehensive building </option>
<option <?php if ($myrow [wuyeleixing]==8) Echo ("selected");? > value= "8" > Farm and Pasture </option>

<option <?php if ($myrow [wuyeleixing]==9) Echo ("selected");? > value= "9" > Commercial and residential building </option>
<option <?php if ($myrow [wuyeleixing]==10) Echo ("selected");? > value= "Ten" > Hotel restaurants </option>
<option <?php if ($myrow [wuyeleixing]==11) Echo ("selected");? > value= "One" > School buildings </option>

</select>

Radio The default selection implementation of a radio box
Copy Code code as follows:

<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");? >> Collective

default selection implementation for checkbox checkbox
Copy Code code as follows:

<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= "italics _gb2312" ><input
name= "Fujia_chuju" type= "checkbox" value= "Chuju" <?php if ($ Myrow[fujia_chuju]) echo ("checked");? >></font></strong> kitchenware </td>
<td width= "height=" "1" ><strong><font color = "#008080" face= "italics _gb2312" ><input
name= "Fujia_woju" type= "checkbox" value= "Woju" <?php if ($myrow [Fujia _woju]) echo ("checked");? >></font></strong> bedding </td>
<td width= "height=" 1 "><strong><font color = "#008080" face= "italics _gb2312" ><input
name= "Fujia_tv" type= "checkbox" value= "TV" <?php if ($myrow [FUJIA_TV] ) echo ("checked");? >></font></strong> TV

The use of these form fields is appropriate to modify some database records and keep the original record as it was added!

Select is selected by default and select Gets the selected item

All right, have to admit, my JS is how the dish, can only read a few lines of code are sometimes difficult, such as today to solve the front End Select default selected problem It took me nearly half an hour, and finally found this code to resolve select to get the selected item quite simply, The selection of the HTML Select to solve with this JS is still very effective, select the selected solution I think it is worth saving and share with friends. The code is as follows:

Copy Code code as follows:

<form name= "form" method= "POST" action= "enctype=" Multipart/form-data ">
<select name= ' aaa ' id= ' BBB ' >
<option value= ' > 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= ' Jilin ' > Jilin </option><option value= ' Liaoning ' > Liaoning </option>
</select>
</form>
<script type= "Text/java script" >
<!--
Document. FORM.bbb.value = "Yunnan";//form is a table single-name, Atc_province is a select tag ID,
Yunnan is select default check
-->
</script>

Hope to help you

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.