1. 程式人生 > >js點選select觸發onchange函式

js點選select觸發onchange函式

點選select 中的不同option,生效日期框填入不同的日期:

<table width="800" border="0">
        <tr> 
          <td width="180" class="LABEL">狀態:</td>
          <td width="140" > 	
            <select name="status" id="PDStatus"  onchange="changeEffDate(this.options[this.options.selectedIndex].value)"
> <option value="0" selected > </option> <option value="1" > 未申請 </option> <option value="2" > 申請通過</option> <option value="3" > 已撤銷 </option> </select> </td> <
td width="120" class="LABEL">生效日期:</td> <td width="134"> <input type="text" name="effectiveDate" id="effectiveDate" maxlength="10" size="12" value=""> </td> <td width="140" class="LABEL">&nbsp;</td> <td width=
"120"> &nbsp; </td> </tr> </table>

script函式:

function changeEffDate(num){
	var Termdte = "";//yyyy/MM/dd
	var dateNow = getNowFormatDate();
	if("1"==num) document.getElementById("effectiveDate").value =Termdte;
	if("23".indexOf(num)>=0) document.getElementById("effectiveDate").value =dateNow;
	if("0"==num)document.getElementById("effectiveDate").value="";
}