これは StackOverflow に関する私の最初の投稿です。この Web サイトのコード スニペットに関する多くのページを読みましたが、常に適切な回答とアドバイスを提供してくれます。
しかし今、私はいくつかの支援を必要としています..複数の入力フィールドにデータを入力したいので、JavaScript にフィールド ID を追加しようとしましたが、今のところうまくいきません。
<script type="text/javascript">
<!--
function calculateAge(inputFieldId, outputFieldId, alert_18){
var age;
var input = document.getElementById(inputFieldId).value;
// Past date info
var pyear = parseInt(input.substring(6,10));
var pmonth = parseInt(input.substring(0,2)) - 1;
var pday = parseInt(input.substring(3,5));
// Today info
today = new Date();
year = today.getFullYear() ;
month = today.getMonth();
day = today.getDate();
if ( month < pmonth ){
age = year - pyear - 1;
}
else if ( month > pmonth ){
age = year - pyear;
}
else if ( month == pmonth ){
if ( day < pday ){
age = year - pyear - 1;
}
else if ( day > pday ){
age = year - pyear;
}
else if ( day == pday ){
age = year - pyear;
}
}
document.getElementById(outputFieldId).value = age;
document.getElementById(outputFieldId).value = age2;
if(alert_18 == 'true'){
if(age < 18){
//Customize alert message
alert('Attention: under 18!');
}
}
}
//-->
</script>
どんな助けでも大歓迎です