简体   繁体   English

我的Optin表单在Internet Explorer中不起作用,但在Firefox中可以正常工作

[英]My Optin form doesn't work in Internet Explorer, but works fine in Firefox

I have the following code for my optin form: 我的optin表单具有以下代码:

<script language="JavaScript">
function checkSub() {
    if (document.signup.email.value.indexOf('@', 0) == -1) {
        alert("Please fill in your valid Email address.\nYour email should be in the following format: email@address.com");
        document.signup.email.focus();
        return false
    }

    else if (!document.signup.terms.checked) {
        alert("You must read and agree to the terms");
        document.signup.terms.focus();
        return false
    }

    else {
        switch (document.signup.extra1.value) {
        case "Platinum":
            answer = confirm("By clicking OK you confirm that you have\nalready entered  
                     the World Cup Giveaway\nas a Platinum upgrade contributor.\n\nIf you have 
                     not yet entered the giveaway\nclick Cancel.\n\nYou can enter using the 
                     link at the\nbottom of the page.\n\nIf you have already entered the 
                     giveaway\nusing a link other than my invitation link\nyou are not 
                     eligible for this offer.");
            if (!answer) {
                return false
            }
            break;
        case "Gold":
            answer = confirm("By clicking OK you confirm that you have\nalready entered  
                    the World Cup Giveaway\nas a Gold upgrade contributor.\n\nIf you have not 
                    yet entered the giveaway\nclick Cancel.\n\nYou can enter using the link
                    at the\nbottom of the page.  \n\nIf you have already entered the
                    giveaway\nusing a link other than my invitation link\nyou are not eligible 
                    for this offer.");
            if (!answer) {
                return false
            }
            break;


        default:
            alert("You must sign up as a contributor to the \nWorld Cup Giveaway to take 
                advantage of \nthis offer.\n\nPlease click the link at the bottom of this 
                \npage or at the blog post mentioned below \nto sign up.\n\nIf you have 
                already signed up using \nthis link, please select the upgrade level\nyou 
                chose on signup or select \"Free\" if \nyou signed up as a free 
                contributor.\n\nIf you have already entered the giveaway\nusing a link other 
                than my invitation link\nyou are not eligible for this offer.\n\nNote:  This 
                page may not function properly\nif viewed in languages other than English.");
            return false
        }
    }
}
</script>

And the HTML 和HTML

<form action="http://ebizac.com/ar/optin.php" method="post" name="signup"
onsubmit="return checkSub()">
    <input type=hidden name="action" value="addlead">
    <input type=hidden name="member" value="2315">
    <input type=hidden name="auto" value="7584">
    <input type=hidden name="thankyou" value="http://plr.forinternetnewbies.com/Offer1">
    <input type=hidden name="resubsetting" value="Y">
    <input type=hidden name="resubredirect" value="">
    <input type=hidden name="invalid_redirect" value="">
    <div style="padding:0 0 0 10px;">
        <table border=0 cellspacing=0 cellpadding=2>
            <tr>
                <td class="label">
                    <font size="2" face="arial, verdana">
                        Name:
                    </font>
                </td>
                <td>
                    <input type=text size=20 name="fname">
                </td>
            </tr>
            <tr>
                <td class="label" width="150">
                    <font size="2" face="arial, verdana">
                        Email address:
                    </font>
                    </span>
                </td>
                <td>
                    <input type=text size=20 name="email">
                </td>
            </tr>
            <tr>
                <td class="label">
                    <font size="2" face="arial, verdana">
                        Upgrade Level:
                    </font>
                </td>
                <td>
                    <select size=1 name="extra1">
                        <option>
                            Haven't Joined Yet
                        </option>
                        <option>
                            Platinum
                        </option>
                        <option>
                            Gold
                        </option>
                        <option>
                            Silver
                        </option>
                        <option>
                            Free
                        </option>
                </td>
            </tr>
            <tr>
                <td>
                </td>
                <td align=center>
                    <input type="checkbox" name="terms" value="agree">
                    I agree to the terms as described on the
                    <a href="http://short9.com/blog0522-sp" target="_blank">blog post</a>
                </td>
            </tr>
            <tr>
                <td>
                </td>
                <td align=center>
                    <input type="submit" value="Contribute Now">
                </td>
            </tr>
        </table>
    </div>
</form>

Everything does what I expect in Firefox, but in Internet Explorer the switch statement always goes to the default case. 一切都按照我在Firefox中的预期进行,但是在Internet Explorer中,switch语句始终使用默认情况。 I tested with an extra alert(signup.extra1.value) in the default case and it shows an empty string. 我在默认情况下使用额外的alert(signup.extra1.value)进行了测试,它显示了一个空字符串。

What could be the problem here? 这可能是什么问题?

不知道这是不是原因(现在无法测试),但是您可能想要尝试更正<script>元素:

<script type="text/javascript" charset="utf-8">

I don't know what the problem is exactly, but when IE is giving JavaScript issues, I use the debugger built into it. 我不知道到底是什么问题,但是当IE出现JavaScript问题时,我会使用内置的调试器。 (IE8) I would put (IE8)我会把

debugger;

right before your switch and use the Watch window to find the value of 在您切换之前,然后使用“监视”窗口查找

document.signup.extra1.value

and all of its pieces. 及其所有片段。

Your option tags needs to have "value" attributes. 您的选项标签需要具有“值”属性。 You should check against those. 您应该检查那些。

<option value="1">Gold</option>
<option value="2">Platinum</option>

Then in your script: 然后在您的脚本中:

switch(document.form_name.select_name.value) {
   case '1': alert("Gold"); break;
   case '2': alert("Platinum"); break;
}

You are most likely having the same issue as in Javascript returns Nan in IE, FF ok 您最有可能遇到与javascript中相同的问题,即IE,FF中返回Nan。

First of all, replace the language="JavaScript" with type="text/javascript" . 首先,将type="text/javascript"替换为language="JavaScript" type="text/javascript" The first one was deprecated a loong time ago. 第一个在很久以前就弃用了。

Secondly, do not access form elements in that way as it is very fragile You might have better luck with accessing the forms elements using 其次,不要以这种方式访问​​表单元素,因为它非常脆弱。使用以下方式访问表单元素可能会更好。

  • give the elements id's and use document.getElementById("foo") 给出元素ID并使用document.getElementById(“ foo”)
  • document. 文献。 forms .signup. 表单 .signup。 elements .extra1 元素 .extra1

Both these are better approaches than what you are doing now. 这两种方法都比您现在做的更好。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 提交按钮不适用于Chrome或Firefox,但适用于Internet Explorer - The Submit Button doesn't work in Chrome or Firefox, but Works in Internet Explorer 为什么基于setTimeout的代码不能在Firefox中以很小的超时时间运行(在Internet Explorer / Chrome中运行)? - Why doesn't this setTimeout-based code work in Firefox with a small timeout (works in Internet Explorer/Chrome)? getElementsByTagName()。length在Firefox / Internet Explorer中不起作用 - getElementsByTagName().length doesn't work in Firefox / Internet Explorer 此代码在使用 Internet Explorer 打开时工作正常,但在我使用 firefox 或其他浏览器打开时无法工作 - This code works fine when opened with internet explorer but fails to work when i open it with firefox or other browsers JavaScript Button.click() 在 Firefox 中不起作用,在 Internet Explorer 中工作正常 - JavaScript Button.click() does not work in Firefox, works fine in Internet Explorer .js代码中给出的document.location()函数在Internet Explorer中可以正常工作,但在Firefox中不起作用 - document.location() function given in the .js code works fine in Internet Explorer but does not work in Firefox 我的代码在Firefox中有效,但在Internet Explorer中不起作用 - My code works in Firefox but not Internet Explorer Ajax调用冻结了Internet Explorer中的UI,但在firefox中工作正常 - Ajax call freezes UI in internet explorer but works fine in firefox 页面在 Firefox 中无法正常工作,但在 chrome 中工作正常 - Page doesn't work as intended in Firefox but works fine in chrome 为什么我的Twitter按钮在Internet Explorer 7中不起作用? - Why doesn't my Twitter button work in Internet Explorer 7?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM