AMMA
AMMA

Reputation: 111

Not sure if I am getting javascript or jquery error

I have below code with jquery. Is jquery not working? I have two alertbox in javascript but second alertbox does not show and first alertbox show. No console errors.

    function validateForm(){
       alert("start of validateForm"); <-- this line show
        var errMsg = "";
        if ($("#accountName").val() == ""){
            $("#accountName").attr("class", "text_field text2 error_yellow");
            errMsg = errMsg + "<tld:label id="registration.step1.error.accountname" />";
        }
        else{
            $("#accountName").attr("class", "text_field text2");
        }
        alert("validateForm"); <-- Not going to this line
        ...................
    }

<s:form action="registration" method="post" id="registrationForm">

    <div class="field_input">
        <select name="registrationForm.accountName" 
        value="${registrationForm.accountName}"
        styleId="accountName" styleClass="text_field text2">
            <option value=""><tld:label id="reg1.request.detail14" /></option>
            <option
                value="<%=MembersiteConstant.MEMBER_ACCOUNT_TYPE_CREDIT_CARD%>"><tld:label id="registration.step1.option.card" /></option>
            <option
                value="<%=MembersiteConstant.MEMBER_ACCOUNT_TYPE_HP_PL%>"><tld:label id="registration.step1.option.loan" /></option>
        </select>
    </div>

<a id="a_btn_submit" href="javascript:validateForm()" class="formButton"><tld:label id="registration.button.next" /></a>

Upvotes: 0

Views: 60

Answers (1)

Nishanth Matha
Nishanth Matha

Reputation: 6081

Your string isn't enclosed properly in this line:

errMsg = errMsg + "<tld:label id="registration.step1.error.accountname" />";

Try replacing it with:

errMsg = errMsg + "<tld:label id='registration.step1.error.accountname' />";

Or

errMsg = errMsg + "<tld:label id=\"registration.step1.error.accountname\" />";

P.S: As a pro tip always use your browser console to view JS error. Press f12 in chrome or ie or ff to view browser console and then navigate to console menu to view JS errors

Upvotes: 1

Related Questions