以下のコードがあり、Javaスクリプトが「未定義またはnull参照のプロパティ '値'を取得できません」というエラーをスローしています。私は何が間違っているのですか?以下は、1つの入力フィールドを検証するために実行しようとしているサンプルコードです。
<html lang="en" xml:lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<meta content="text/html;charset=iso-8859-2" http-equiv="content-type" />
<script type="text/javascript">
function validate_frm_new_user_request()
{
alert('test');
valid = true;
if ( document.frm_new_user_request.u_isid.value == '' )
{
alert ( "Please enter your valid ISID Information." );
document.frm_new_user_request.u_isid.focus();
valid = false;
}
return valid;
</script>
</head>
<body
<form method="post" action="" name='frm_new_user_request' id="frm_new_user_request" onsubmit="return validate_frm_new_user_request();">
<center>
<table>
<tbody>
<tr align="left">
<td><Label>ISID<em>*:</Label><input maxlength="15" id="u_userid" name="u_userid" size="20" type="text"/></td>
<td>
<tr>
<td align="center" colspan="4">
<input type="image" src="images/button/btn_create_request.gif" border="0" ALT="Create New Request">
</td>
</tr>
</table>
</form>
</body>
</html>
問題は、どのように値を取得しようとしているのかです。のようなもの...
if ( document.frm_new_user_request.u_isid.value == '' )
動作しません。最初に値を取得する要素を見つける必要があります。これは、オブジェクトの参照名とピリオドを入力して値を取得または割り当てることができるサーバーサイド言語とはまったく異なります。
document.getElementById('[id goes here]').value;
働くでしょう。注:JavaScriptでは大文字と小文字が区別されます
私は使用することをお勧めします:
var variablename = document.getElementById('[id goes here]');
または
var variablename = document.getElementById('[id goes here]').value;
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加