2016-08-07 7 views
0

私は倉庫からのものを作成しましたが、毎回日付+時刻を記入しなければならないと感じていません。時間、jsを使用して? DD/MM/YYYYのH:MM が、これは私のコードです:自動時間要素js

<html> 
 
<iframe src ="adminview.html" scrolling="no" height ="100"></iframe> 
 
    <!--this is the date and time script I am using to try to fill the input--> 
 
<script> 
 
var today = new Date(); 
 
var UTCstring = today.toUTCString(); 
 
</script> 
 
<form action =""> 
 
    Name of employee:<br> 
 
<input type ="text"></input> 
 
    Item no.:<br> 
 
<input type ="text"></input> 
 
    Quantity of item:<br> 
 
<input type ="text"></input> 
 
<!--this is the input I am trying to fill with the above js--> 
 
<input type ="hidden" value="UTCstring"></input> 
 
</form> 
 
</html>

+0

、それは手動で設定することができない場合は、その理由だけで時間を追加しないですサーバ? – Ties

+0

日付/時刻の事前設定の後ろの意図は容易であるか、またはTiesがそれが修正されていることを尋ねるように、サーバー側で設定できますか?純粋により良いユーザーエクスペリエンスの場合は、ドキュメントの負荷でそれをあらかじめ設定することができます – Adil

+0

はい私はあなたがサーバー側でそれを行うことができますよー、しかし私はPHPで時間を行うhpwを知らなかった – 500man

答えて

0

あなたの隠された入力ID(例:日付フィールド)を得た私はこのような完全な日付+時刻を希望し、これをスクリプトに追加してください。 -

document.getElementById('dateField').value = UTCstring; 

上記の行は、非表示の日付フィールドを見つけてその値を設定します。この値を使用して、デフォルトのフォームをフォームに入力できます。 (あなたはクライアント側でそれをしたい場合)

ここで更新されたコード

<html> 
 
<iframe src ="adminview.html" scrolling="no" height ="100"></iframe> 
 
    <!--this is the date and time script I am using to try to fill the input--> 
 
<script> 
 
var today = new Date(); 
 
var UTCstring = today.toUTCString(); 
 
document.getElementById('dateField').value = UTCstring; // or today.toUTCString(); 
 
</script> 
 
<form action =""> 
 
    Name of employee:<br> 
 
<input type ="text"></input> 
 
    Item no.:<br> 
 
<input type ="text"></input> 
 
    Quantity of item:<br> 
 
<input type ="text"></input> 
 
<!--this is the input I am trying to fill with the above js--> 
 
<input id="dateField" type ="hidden"></input> 
 
</form> 
 
</html>

関連する問題