プロが教えるわが家の防犯対策術!

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=EUC-JP">
<title>Test</title>
<script language="javascript"><!--
//ロード時に、現在の年と月に合わせて表示・選択する//
function tDate(){
dt = new Date();
y = dt.getFullYear();
m = dt.getMonth()+1;
d = dt.getDate();
//2009年以降を順にセレクトメニューへ追加//
var ny=y-2009
document.selectform.toshi.length = ny+1;
for (i=0; i<=ny; i++) {
document.selectform.toshi.options[i].text = y-i + "年";
document.selectform.toshi.options[i].value = y-i ;
}
document.selectform.tsuki.length = 12;
for (i=0; i<12; i++){
document.selectform.tsuki.options[i].text = i+1 + "月";
document.selectform.tsuki.options[i].value = i+1 ;
if(i == m-1){
document.selectform.tsuki.options[i].selected = "selected";
}
}
document.selectform.hi.length = 31;
for (i=0; i<31; i++) {
document.selectform.hi.options[i].text = i+1 + "日";
document.selectform.hi.options[i].value = i+1 ;
if(i == d-1){
document.selectform.hi.options[i].selected = "selected";
}
}
};

function argDate(){
YY = document.selectform.toshi.options[document.selectform.toshi.selectedIndex].value;
MM = document.selectform.tsuki.options[document.selectform.tsuki.selectedIndex].value;
if (parseInt(MM)<10) MM = "0" + MM
DD = document.selectform.hi.options[document.selectform.hi.selectedIndex].value;
if (parseInt(DD)<10) DD = "0" + DD
var filename = "./Sample_"+YY+MM+DD+"_test.png";
document.images["image0"].src = filename;
alert(YY+MM+DD); //確認
};
//-->
</script>
</head>
<body onLoad="tDate()">
<form method="post" name="selectform" action="#">
<select name="toshi"></select>
<select name="tsuki"></select>
<select name="hi"></select>
<input type="submit" value="OK" onClick="argDate()">
</form>
<img name="image0" height="600" width="800">
</body>
</html>
以上のコードで、formの年月日を変更し、それに伴うimageを表示させたいのですが、一時的に表示されるもののonLoadされてしまい、過去の画を見ることができせん。どのようにしたらいいかご教示ください。

A 回答 (1件)

ブラウザによって多少違う可能性もあるけど、formでsubmitしているので、スクリプト実行後にactionを実行しようとしているのではないのかな?



return falseでキャンセルするか、input type="submit"をinput type="button" などに変えたらどうなるでしょうか?
    • good
    • 0
この回答へのお礼

fujillinさま
的確なご指摘ありがとうございます。
問題を無事解決できました。
submitの使い方を正しく理解してなっかたのが原因だと思います。
submitだとformのactionに対して動作する?そしてaction随時ページが更新され、onLoadされる。
buttonの場合、javascriptと併用し、指示したfunction()関数へ動作する。何に対するactionなのか明確になる。
と今回理解しておきます。

お礼日時:2009/01/07 21:05

お探しのQ&Aが見つからない時は、教えて!gooで質問しましょう!