0

http://business.uglyopportunities.com/affiliate-signup/のページにサインアップ フォームがあります(下にスクロールしてフォームを表示します)。

覚えておいてください、私はJSがあまり得意ではないので、これは単純なエラーかもしれません.

とにかく、検証するように指示するフォームの最初の行は次のとおりです。

<form accept-charset="UTF-8" action="xxxxx" class="infusion-form" method="POST" name="myform" onsubmit="return validateForm();">

ここに私のvalidateForm JavaScriptがあります:

<script type="text/javascript">
function validateForm() {
    var a = document.forms["myform"]["inf_field_FirstName"].value;
    var b = document.forms["myform"]["inf_field_Email"].value;
    var c = document.forms["myform"]["inf_field_Phone1"].value;
    var d = document.forms["myform"][" inf_field_StreetAddress1"].value;
    var e = document.forms["myform"][" inf_field_City"].value;
    var f = document.forms["myform"][" inf_field_State"].value;
    var g = document.forms["myform"][" inf_field_PostalCode"].value;
    var h = document.forms["myform"][" inf_other_Username"].value;
    var i = document.forms["myform"][" inf_other_Password"].value;
    var j = document.forms["myform"][" inf_other_RetypePassword"].value;

    if (a == null || a == "" || a == "First Name Here") {
        alert("Please enter your First Name!");
        return false;
    }
    if (c == null || c == '' || c == "Enter Your Phone Here" || c.length < 9) {
        alert("Please insert your phone number!");
        return false;
    }
    if (d == null || d == '' || d == "Street Address”) {
        alert("Please insert your street address ");
        return false;
    }
    if (e == null || e == '' ||e == "City”) {
        alert("Please insert your city");
        return false;
    }

    if (f == null || f == '' || f == "State”) {
        alert("Please insert your state ");
        return false;
    }

    if (g == null || g == '' ||g == "Postal Code”) {
        alert("Please insert your postal code");
        return false;
    }
    if (h == null || h == '' || h == "Username”) {
        alert("Please insert your username ");
        return false;
    }
    if (i == null || i == '' ||i == "password”) {
        alert("Please insert your password");
        return false;
    }
    if (j == null || j == '' || j == "password”) {
        alert("Please re - type your password ! ");
        return false;
    }




    var emailRegEx = /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i;
    if (document.myform.inf_field_Email.value.search(emailRegEx) == -1) {
        alert("Please enter a valid email address.");
        return false;
    }
}
</script>

それは機能していません。ただし、このコードを使用すると、正常に機能しました。

<script type="text/javascript">
function validateForm() { 
    var a=document.forms["myform"]["inf_field_FirstName"].value; 
    var b=document.forms["myform"]["inf_field_Email"].value; 
    var c=document.forms["myform"]["inf_field_Phone1"].value; 
    if (a==null || a=="" || a=="First Name Here") {   
        alert("Please enter your First Name!");
        return false;
    }
    if (c==null || c==''|| c=="Enter Your Phone Here" || c.length < 9) {
        alert("Please insert your phone number!");
        return false;
    }

    var emailRegEx = /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i;
    if (document.myform.inf_field_Email.value.search(emailRegEx) == -1)  {
        alert("Please enter a valid email address.");
        return false;
    }
}
</script>

更新されたコード*

<script type="text/javascript">// <![CDATA[
function validateForm() {
    var a = document.forms["myform"]["inf_field_FirstName"].value;
    var b = document.forms["myform"]["inf_field_Email"].value;
    var c = document.forms["myform"]["inf_field_Phone1"].value;
    var d = document.forms["myform"]["inf_field_StreetAddress1"].value;
    var e = document.forms["myform"]["inf_field_City"].value;
    var f = document.forms["myform"]["inf_field_State"].value;
    var g = document.forms["myform"]["inf_field_PostalCode"].value;
    var h = document.forms["myform"]["inf_other_Username"].value;
    var i = document.forms["myform"]["inf_other_Password"].value;
    var j = document.forms["myform"]["inf_other_RetypePassword"].value;

    if (a == null || a == "" || a == "First Name Here") {
        alert("Please enter your First Name!");
        return false;
    }
    if (c == null || c == '' || c == "Enter Your Phone Here" || c.length < 9) {
        alert("Please insert your phone number!");
        return false;
    }
    if (d == null || d == '' || d == "Street Address") {
        alert("Please insert your street address ");
        return false;
    }
if (e == null || e == '' ||e == "City") {
        alert("Please insert your city");
        return false;
    }

    if (f == null || f == '' || f == "State") {
        alert("Please insert your state ");
        return false;
    }

if (g == null || g == '' ||g == "Postal Code") {
        alert("Please insert your postal code");
        return false;
    }
    if (h == null || h == '' || h == "Username") {
        alert("Please insert your username ");
        return false;
    }
if (i == null || i == '' ||i == "password") {
        alert("Please insert your password");
        return false;
    }
    if (j == null || j == '' || j == "password") {
        alert("Please re - type your password ! ");
        return false;
    }




    var emailRegEx = /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i;
    if (document.myform.inf_field_Email.value.search(emailRegEx) == -1) {
        alert("Please enter a valid email address.");
        return false;
    }
}
// ]]>
</script>
4

2 に答える 2

1

ここに空白があります:

var d = document.forms["myform"][" inf_field_StreetAddress1"].value;
//                                ^-----------------------

あなたは同じ問題を抱えていますe,f,g,h,i,j

また、間違った引用符記号を使用しました。

"Street Address”
//             ^--------------

あなたはそれを数回しました。

于 2013-01-19T21:52:12.457 に答える
0

gdoron が言うように、おそらくスペルの問題です。要素の名前を空白で始めることはできませんhttp://www.w3.org/TR/html401/types.html#type-name

于 2013-01-19T21:58:59.017 に答える