检查文本是否为空

时间:2013-05-26 11:54:09

标签: javascript html

<html dir = rtl>
    <head>
        <title> </title>
        <meta HTTP-EQUIV="Content-language" CONTENT="ar">
        <script type="text/javascript">
            function CheckForm(String)
            {
                 var pNames = [ "sName", "sAge", "sAddress"];
                 for (var i = 0; i < 4;i++)
                 {
             if (Infi[i].value == "")
                         document.getElementById(pNames[i]).innerHTML = 'عفواً لاتوجد قيمة في الحقل';
                 }
            }

        </script>
    </head>
    <body>
       <form name = "Info" method = "set" action = "#">
           <table  border = "0" width = "80%" align = "center">
               <tr>
                   <td align = "left"> الاســــــــــــــــم: </td>
                   <td > <input type="text" name = "CurName" size = "31"> <p id = "sName" style = "display: inline"> </p> </td>
               </tr>

               <tr>
                   <td align = "left"> العــــــــــــــــمر :</td>
                   <td> <input type = "text" name = "CurAge" size = "10"> <p id = "sAge" style = "display: inline"> </p> </td>
               </tr>

               <tr>
                   <td  align = "left"> العنـــــــــــــوان :</td>
                   <td> <input type = "text" name = "CurAddress" size = "45"> <p id = "sAddress" style = "display: inline"> </p> </td>
               </tr>

               <tr>
                   <td  align = "left"> الحالــــــــــــــــة :</td>
                   <td> <input type = "radio" name = "Mar" > متزوج<input type = "radio" name = "Sin" checked="yes"> أعزب </td>
               </tr>

               <tr>                   
                  <td colspan = 2 align = center> <button type = "button" onclick = "CheckForm(); return false;">ارسال </button>  <button type = "reset">مسح</button> </td>                 
               </tr>
          </table>
       </form>
    </body>
</html>

我想检查表格框是否为空,我试了很多但没有什么效果好所以请任何人都可以帮助我,抱歉我的英文不好

3 个答案:

答案 0 :(得分:3)

您的表单名称为Info,而不是Infi。看来你有一个错字。

此:

if (Infi[i].value == "")

应该是这样的:

if (Info[i].value == "")

答案 1 :(得分:2)

您必须更正代码中的拼写错误:

表单名称必须为Info,而不是Infi

答案 2 :(得分:1)

Infi未定义错误。您没有定义infi ..