TOP ▲
itcore TOP
> TIPS
> jClear.php
タグ:html javascript クリアボタン 手製のクリアボタンで各フィールドをクリア(または初期値を設定)する。HTML, JavaScript | itcore 2017年
<form action=# method=post>
<input type=text name=text1 value=''><br>
<input type=checkbox name=checkbox1 value=1><br>
<input type=radio name=radio1 value=1>A<br>
<input type=radio name=radio1 value=2>B<br>
<select name=select1[] size=5 multiple id=select1><br>
<input type=button value='クリア' onClick="jClear();"><br>
</form>
<SCRIPT>
//初期クリア
function jClear() {
document.forms[0].text1.value = "";
document.forms[0].checkbox1.checked = true;
document.forms[0].radio1[0].checked = true;
var obj = document.getElementById("select1"); obj.selectedIndex = -1;
}
</SCRIPT>