2016-08-15 124 views
0

我有2個日期輸入,我想將mincheckout設置爲值checkin第二個日期大於javascript中的第一個日期

Check In 
<input type="date" id="checkIn" name="checkIn"> 

Check out 
<input type="date" id="checkOut" min="" name="checkOut"> 

這個想法是在用戶輸入第一個日期之後,簽出日期大於簽入日期。

我已經用這樣的嘗試(適用於電話號碼,但沒有日期)

function updatedate() { 
    var firstdate = document.getElementById("checkIn").value; 
    document.getElementById("checkOut").min = firstdate; 
} 

使用onclick爲輸入。

任何建議將是偉大的謝謝你。

+1

的可能的複製[用JavaScript比較兩個日期](http ://stackoverflow.com/questions/492994/compare-two-dates-with-javascript) –

回答

0

試試這個

<label>Check In</label> 
<input type="date" id="checkIn" name="checkIn" onchange="updatedate();"> 

<label>Check out</label> 
<input type="date" id="checkOut" min="" name="checkOut"> 

-

function updatedate() { 
    var firstdate = document.getElementById("checkIn").value; 
    document.getElementById("checkOut").value = ""; 
    document.getElementById("checkOut").setAttribute("min",firstdate); 
    } 
+0

謝謝。很棒。 – Lachlanf

0

您的代碼適用於設置最小值。使用第一個輸入change事件來更新第二輸入最低,而不是click

​​

相關問題