dポイントプレゼントキャンペーン実施中!

雑誌やネットを調べ、ラジオボタンで入力項目の可・不可を切り替える
JavaScriptを見つけたのですが、思うように動作しません。

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitio …
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=shift_jis" />
<title>Sample</title>
<script type="text/javascript">
<!--
function radioChange() {
if(document.form1.radioSelect[0].checked == true) {
document.form1.04text.disabled = false;
document.form1.04text.style.backgroundColor='#FFFFFF';
document.form1.05text.disabled = false;
document.form1.05text.style.backgroundColor='#FFFFFF';
document.form1.06text.disabled = false;
document.form1.06text.style.backgroundColor='#FFFFFF';
document.form1.07text.disabled = true;
document.form1.07text.style.backgroundColor='#D4D0C8';
document.form1.08text.disabled = true;
document.form1.08text.style.backgroundColor='#D4D0C8';
document.form1.09text.disabled = true;
document.form1.09text.style.backgroundColor='#D4D0C8';
} else if(document.form1.radioSelect[1].checked == true) {
document.form1.04text.disabled = true;
document.form1.04text.style.backgroundColor='#D4D0C8';
document.form1.05text.disabled = true;
document.form1.05text.style.backgroundColor='#D4D0C8';
document.form1.06text.disabled = true;
document.form1.06text.style.backgroundColor='#D4D0C8';
document.form1.07text.disabled = false;
document.form1.07text.style.backgroundColor='#FFFFFF';
document.form1.08text.disabled = false;
document.form1.08text.style.backgroundColor='#FFFFFF';
document.form1.09text.disabled = false;
document.form1.09text.style.backgroundColor='#FFFFFF';
} else {
document.form1.04text.disabled = true;
document.form1.04text.style.backgroundColor='#D4D0C8';
document.form1.05text.disabled = true;
document.form1.05text.style.backgroundColor='#D4D0C8';
document.form1.06text.disabled = true;
document.form1.06text.style.backgroundColor='#D4D0C8';
document.form1.07text.disabled = true;
document.form1.07text.style.backgroundColor='#D4D0C8';
document.form1.08text.disabled = true;
document.form1.08text.style.backgroundColor='#D4D0C8';
document.form1.09text.disabled = true;
document.form1.09text.style.backgroundColor='#D4D0C8';
}
}
//-->
</script>
</head>
<body onload="radioChange()">
<form action="" method="post" name="form1">
<table>
<tr>
<td>
<input name="radioSelect" type="radio" onclick="radioChange()" value="1" />
国内旅行
<input name="radioSelect" type="radio" onclick="radioChange()" value="0" />
海外旅行</td>
</tr>
<tr>
<td></td>
</tr>
<tr>
<td>
国内編:<br />
希望地
<input type="text" name="04text" />
<br />
希望日:
<input type="text" name="05text" />
<br />
乗り物:
<input type="text" name="06text" />
</td>
</tr>
<tr>
<td></td>
</tr>
<tr>
<td>海外編:<br />
希望地
<input type="text" name="07text" />
<br />
希望日:
<input type="text" name="08text" />
<br />
乗り物:
<input type="text" name="09text" />
</td>
</tr>
</table>
</form>
</body>
</html>

テキストボックスの「name」を、英字から始めれば解決するのですが
事情があり、nameを数字で始める必要があります。
この解決方法を教えていただけませんでしょうか。
よろしくお願いいたします。

A 回答 (2件)

document.form1.04text.・・・



document.form1.elements['04text'].・・・
    • good
    • 0
この回答へのお礼

ありがとうございました。

とても助かりました!

お礼日時:2008/11/21 15:00

document.form1.04text.disabled ではなく


document.getElementsByName("04text")[0].disabled にする。
    • good
    • 0

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