2012-11-08 54 views
0

我有1個下拉框和2個輸入字段。在其他輸入字段中自動增加日期

當我選擇從下拉的值,(我把值12個月和60個月內)看到的畫面

Select the number of months

,當我採取與jquery的日期選擇器等'08的日期/ 11/2012' 看後面的圖像

Select the Date with Datepicker

然後我想在第二inputfield自動獲取與+ 12個月的日期 - '08 /2013分之11' 看到圖片

Increase the Date automatically from the value of the dropdown

所以,當我把一個值60個月,那麼它必須算上+ 60月08一樣/二千○一十七分之一十一'

我不知道該怎麼意識到這一點。 所有值來自於一個MySQL數據庫

這裏是我的代碼我現在有:

<table id="BLth1B" cellspacing="0" > 
     <tr> 
      <td id="BLth1" colspan="3">&nbsp;&nbsp;JUGEMENT</td> 
     </tr> 
     <tr> 
      <td id="mySaisie">&nbsp;Régime</td> 
      <td id="mySaisie">&nbsp;Date Jugement</td> 
      <td id="mySaisie" >&nbsp;Date de Fin</td> 
     </tr> 
     <tr> 
      <td> 
      <select id="basic-combo" name="basic-combo"> 
      <option value="0"></option> 
    <?php 

    $QryRegime = "SELECT id_regimes, regimes_ref, mois_reg FROM amep_regimes"; 
    $ResRegime = mysql_query($QryRegime) OR die(mysql_error()); 

    while($rowregime = mysql_fetch_assoc($ResRegime)) { 
    echo "<option value=". $rowregime['id_regimes'] .">" . $rowregime['regimes_ref'] . " - " . $rowregime['mois_reg'] . "&nbsp;</option>"; 
    } 
    ?> 
      </select> 
     </td> 
      <td><input class="input20" id="datumanfang" /></td> 
      <td><input class="input20"/></td> 
     </tr> 
    </table> 

如果有人可以幫我嗎?

提前THX

回答

0

第一件事情,ID應該永遠是獨一無二的,這就是爲什麼它叫做id ......所以一定要改變這個IDS ...

<td id="mySaisie">&nbsp;Régime</td> 
<td id="mySaisie">&nbsp;Date Jugement</td> 
<td id="mySaisie" >&nbsp;Date de Fin</td> 

日期選擇器有這個選項。看看文檔。

http://api.jqueryui.com/datepicker/#method-setDate

和做這樣的事情......

$(function(){ 
    $('#datumanfang').datepicker({ 
     onSelect: function(date,obj){ 
      var selectvalue=$('#basic-combo').val(); // get a select value 
      var addeddate=date.setMonth(date.getMonth() + selectvalue); //add that value 
      $(#idOfLastInput).datepicker("setDate", addeddate); // give and id to the last input... and select that 
     } 
    }); 
}); 

,我建議你使用date.js日期計算,並與日期對象玩耍。

+0

嗨,很抱歉我遲到的迴應。感謝您的幫助。我已經嘗試過你的代碼,但我沒有得到它的工作。我發現你對'date.js'的建議非常有趣。如果你有一個例子(在JSfiddle)對我來說,因爲在網站上我不明白如何實現這一點。 THX – achillix

+0

好的,你在代碼中面臨問題?和約日期js ...你必須加載js文件..並使用其文檔中提到的功能.... – bipen

相關問題