ページの複数のinputテキストを検証するための必須項目

6425 ワード

フロントページJS:
function CheckMustWrite(){
    var count = $("input[mustwrite = 'true']", document.forms[0]);
    for (var i = 0; i< count.length ; i++){
         if(count[i].value == ""){
              alert(count[i].title + "     ");
              count[i].focus();
              return false;
         }    
    }
    var textareas = $("textarea[mustwrite = 'true']", document.form[0]);
    for (var i = 0; i<textareas.length; i++ ){
        if(textareas[i].value == ""){
            alert(textareas[i].title + "     ");
            textareas[i].focus();    
            return false;
        }
    }                  
}        
フロントページHTML:
    <table border="0" cellpadding="5" cellspacing="0" width="100%">      
        <tr>
            <td></td>
            <td><input id="DATA_Name" kind="varchar" mustwrite="true" name="DATA_Name" title="     " type="text"  class="blur_text" value="           " /></td>                          
            <td></td>                          
            <td><input id="DATA_cd" kind="varchar" mustwrite="true" name="DATA_cd" title="    " type="text"  class="blur_text" value="            " /></td>
        </tr>
        <tr>
            <td></td>                     
            <td><input id="DATA_sj" kind="varchar" mustwrite="true" name="DATA_sj" title="     " type="text"  class="blur_text" value="          "  /></td>                          
            <td></td>
            <td><input id="DATA_bm" kind="varchar" name="DATA_bm" title="    " type="text"  value="              "  class="blur_text" /></td>
        </tr>                       
        <tr>         
            <td></td>
            <td colspan="3"><textarea id="DATA_wt" name="DATA_wt" title="     "  class="blur_text" value="" ></textarea></td> 
        </tr>       
        <tr>
            <td></td>                          
            <td colspan="3"><textarea id="DATA_fa" name="DATA_fa" title="     "  class="blur_text" >            </textarea></td>              
        </tr>                                                
    </table>
  <div  align="center">
         <input id="Image1" type="image" src="imgs/submit.png" onclick="return CheckMustWrite()" onserverclick="Button1_Click" runat="server" />
</div>