表格验证IE7

时间:2013-06-04 17:00:29

标签: javascript validation internet-explorer-7

我创建了一个表单,在我测试的任何地方提交并正常工作,除非我使用的是IE7(IE8可能也有问题,我没有机器来测试它。)

当我尝试IE7时,表单将不会提交,JavaScript验证也不起作用。我相信这个问题与JavaScript的工作方式不同,但到目前为止,我测试的所有内容都没有区别。

HTML

<form id="find_agent" action="find_agent_form_processor.asp" onsubmit="return validateAgentForm();" method="POST">
<fieldset>
    <ul id="find_agent_errors">
        <li id="find_agent_first_name_error">Please Enter Your First Name</li>
        <li id="find_agent_last_name_error">Please Enter Your Last Name</li>
    </ul>
    <ul>
        <li>
            <input type="hidden" name="To" value="you@domain.com" />
            <input type="hidden" name="From" value="me@domain.com" />
            <input type="hidden" name="Subject" value="Find Agent" />
        </li>
        <li>
            <strong>First Name: <span class="red_text">*</span></strong>
            <input type="text" name="find_agent_first_name">
        </li>
        <li>
            <strong>Last Name: <span class="red_text">*</span></strong>
            <input type="text" name="find_agent_last_name">
        </li>
    </ul>
</fieldset>
</form>

的JavaScript

function validateAgentForm(){
var count = 0;

var findAgentFirstName = document.forms["find_agent"]["find_agent_first_name"].value;
if(findAgentFirstName.length < 1){
    document.getElementById("find_agent_first_name_error").style.visibility = "visible";
    count++;
}
else{
    document.getElementById("find_agent_first_name_error").style.visibility = "hidden";
}
if(count > 0){
    return false;
}

1 个答案:

答案 0 :(得分:0)

试试这个

     function validateAgentForm(){
        var count = 0;
        var findAgentFirstName = document.forms["find_agent"]["find_agent_first_name"].value;
        if(findAgentFirstName.length < 1){
            document.getElementById("find_agent_first_name_error").style.visibility = "visible";
            count++;
return false;//This will prevent the form from submitting if the text field is empty
        }
        else{
            document.getElementById("find_agent_first_name_error").style.visibility = "hidden";
        }
        }