WEB制作のメモ帳

「javascript」で入力フォームを制限

2011-05-16

javascript

入力フォームの制作で「その他」が選択された時だけ
テキストボックスを有効にしてほしいと依頼されたので
「javascript」による方法をメモ
「その他」選択時のみテキストボックスの書き込みが可能です。

SOURCE
■javascript
function Dture(objId){
document.getElementById(objId).disabled = true;
}
function Dfalse(objId){
document.getElementById(objId).disabled = false;
}

■HTML
<input type="radio" name="reason" value="理由1" onclick="Dture('other_reason');" id="reason" />理由1
<input type="radio" name="reason" value="理由2" onclick="Dture('other_reason');" id="reason" />理由2
<input type="radio" name="reason" value="理由3" onclick="Dture('other_reason');" id="reason" />理由3
<input type="radio" name="reason" value="" onclick="Dfalse('other_reason');" id="reason" />その他
<input type="text" name="other_reason" id="other_reason" />