»
Tiếng AnhTiếng PhápTiếng Việt

In - Điền dữ liệu tự động - JavaScriptBank.com

Phiên bản đầy đủ: jsB@nk » Biểu mẫu » Điền dữ liệu tự động
URL: https://www.javascriptbank.com/autofill-and-select-form-fields.html

Điền dữ liệu tự động © JavaScriptBank.comĐoạn mã này sẽ tạo dữ liệu tự động lên các khung nhập liệu, các trình đơn tùy chọn,... trong một biểu mẫu ngay khi nó vừa được tải xong. Đoạn mã rất dễ cài đặt và chỉnh sửa tùy theo nhu cầu sử dụng.

Phiên bản đầy đủ: jsB@nk » Biểu mẫu » Điền dữ liệu tự động
URL: https://www.javascriptbank.com/autofill-and-select-form-fields.html



JavaScript
<script language="javascript"><!--// Created by: assbach :: http://www.ipernity.com/home/assbachfunction dummyreg() {  var currentDate = new Date();  var month = currentDate.getMonth() +1;  var day = currentDate.getDate();  var year = currentDate.getFullYear();  var formDate = month + "-" + day + "-" + year;  // Use whatever data you like for the items below document.getElementById("name").value = "JavaScriptBank.com"; document.getElementById("email").value = "email@JavaScriptBank.com"; document.getElementById("datebox").value = formDate; document.getElementById("checkbox").checked = true; // checkbox document.getElementById("radiobutton").checked = true; // radiobutton document.getElementById("pulldown").selectedIndex = 1; // dropdown}// Multiple onload function created by: Simon Willison// http://simonwillison.net/2004/May/26/addLoadEvent/function addLoadEvent(func) {  var oldonload = window.onload;  if (typeof window.onload != 'function') {    window.onload = func;  } else {    window.onload = function() {      if (oldonload) {        oldonload();      }      func();    }  }}addLoadEvent(function() {  dummyreg();});//--></script><!--    This script downloaded from www.JavaScriptBank.com    Come to view and download over 2000+ free javascript at www.JavaScriptBank.com-->


HTML
<form>  <table>    <tbody><tr>      <td>Name:</td>      <td><input class="inputBox" id="name" type="text"></td>    </tr><tr>      <td>E-mail:</td><td><input class="inputBox" id="email" type="text"></td>    </tr><tr>      <td>Date</td><td><input class="date" id="datebox" type="text"></td>    </tr><tr>      <td>        <input id="checkbox" name="option1" value="Milk" type="checkbox"> Milk<br>        <input name="option2" value="Butter" type="checkbox"> Butter<br>        <input name="option3" value="Cheese" type="checkbox"> Cheese<br>      </td>      <td>        <input name="heading of button" value="Milk" type="radio"> Milk<br>        <input id="radiobutton" name="heading of button" value="Butter" type="radio"> Butter<br>        <input name="heading of button" value="Cheese" type="radio"> Cheese      </td>    </tr>    <tr>      <td>        <select id="pulldown">          <option>Milk</option>          <option>Coffee</option>          <option>Tea</option>        </select>      </td>      <td>&nbsp;</td>    </tr>  </tbody></table></form><!--    This script downloaded from www.JavaScriptBank.com    Come to view and download over 2000+ free javascript at www.JavaScriptBank.com-->