How to set default value for input in PHP

无忌哥哥
Release: 2023-04-03 06:44:02
Original
6500 people have browsed it

Example Description
Next, the user is introduced to a property similar to the read-only property, which is to set the default value of the text box. Set the default color of the text box to gray, and dynamically change the text box default value information when entering information in the user name.
Key Technology
The key to this example is to set the default value of the text box through the disabled attribute, and then dynamically change the value of the default value text box through related events. The code for setting the default value using the disabled attribute is as follows:

 <input id="0"class="0"type="text"disabled value=&#39;0100521041&#39;/>
Copy after login

Design process
(1) Create a new index.php file, introduce the CSS style sheet file, and write the form. The code is as follows:

  table width="350"border="0"class="p">
  <tr>
  <td width="100">用户名:</td>
  <td align="left"><input class="m"id="name"type="text"/></td>
  </tr>
  <tr>
    <td>职  位:</td>
    <td align="left"><input class="m"type="text"id="type"disabled value="自选选取"/></td>
    </tr>
    </table>
Copy after login

(2) Define a JavaScript script method to dynamically change the default value of the text box. The code is as follows:

    $("#name").keyup(function(){
         var name=$("#name").val();
         var manager=&#39;mr&#39;;
         if(name==&#39;mr&#39;){
                 $("#type").val("经理");
         }else{
               $("#type").val("程序员");
         }
     });
Copy after login

Secret Tips
Regarding setting the default value of the text box.
(1) Setting the default value of the text box and setting the read-only attribute of the text box have the same effect.
(2) When using disabled, just add the attribute name to the mark.

The above is the detailed content of How to set default value for input in PHP. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!