1

我的网站上有一个注册表单,它在 IE 中运行良好,但在 FF 或 Chrome 中无法运行。我曾尝试在这里查看其他有类似问题的论坛帖子,但仍然无法解决这个愚蠢的问题。(我不是代码编写者)。

这是代码

引用

<script type="text/JavaScript">
function validate_form(){
{validation_text}
else{
        return true;
    }
}
var str_vars = '';
function all_fields(){
    str_vars = '';
    el = document.form1;
    for (var i = 0; i < el.elements.length; i++) {
        if (el.elements[i].value != '')
        str_vars += el.elements[i].name+'='+el.elements[i].value+'&';
    }
    str_vars = str_vars.substr(0,str_vars.length-15);;
}
</script>
<div id="div_form" name="div_form">
<form id="form1" name="formx" method="{send_method}" action="{form_switch}">
<p>&nbsp;</p>
<table border="0" width="100%" style="border-collapse: collapse" bordercolor="#111111" cellpadding="0" cellspacing="0">
{error}
{signup_list}
<tr>
    <td align="right">{description_country} &nbsp;</td>
    <td>{shiping_country_list}{required_country}</td>
  </tr>
<tr><td align="right"> {promo}</td></tr>
 {code_signup}
  <tr>
    <td colspan="2"><div align="center">
      <input name="terms" id="terms" value="1" type="checkbox">
      <label for="terms">I accept the <a href="terms.php" target="_blank">terms &amp; conditions</a></label>
    </div></td>
    </tr>
     <tr>
    <td colspan="2"><div align="center">
{captcha}</td>
    </tr>
    {arp_fields}
  <tr>
    <td><div align="right">*</div><br></td>
    <td width="332">Denotes required</td>
  </tr>
  <tr>
    <td>
      <div align="right">
 <input name="Submit" value="Submit" type="button" onclick="{request}{request_email}{form2items}">
        </div></td>
    <td> <br></td>
  </tr>
</table>
</form>

尾引号

任何帮助,将不胜感激。

4

1 回答 1

1

也许代替

el = document.form1;

尝试

 el = document.getElementById('form1');

我看不到所有的 JS,所以很难猜,但要尝试的另一件事是将提交按钮的名称name="Submit"name="submitForm". 如果 form.submit() 在脚本的某个地方被调用,这可能会导致问题。

您的验证函数应如下所示:

function validate_form(){
var form = document.getElementById('form1');
err = 'The following fields are not correct filled:\n';

if (form.first_name.value == ''){
    err += 'No First Name.\n';
}

if (emailCheck(form.email.value) == false){
    err += 'No Valid email.\n';
}

if (form.terms.checked != true){                
    err += 'You did not agree with the terms.\n';
}

if (err != 'The following fields are not correct filled:\n'){
    alert (err);
    return false;
}

else{
        return true;
    }
}

最后,将您的提交按钮更改为: <input name="Submit" value="Submit" type="button" onclick="if (validate_form()) document.getElementById('form1').submit();">

于 2012-08-14T15:04:52.857 回答