2

Hi I have a simple modal popup which has 3 name fields and 3 e mail fields adjacent to each other. I am new to jQuery so can any one please help me how to write a logic for the following case?

The first name field and Email field are mandatory so I kept the class as required fields but the other two name and e-mail fields are optional but if I enter a value in name field I have to enter the value in Email field. In other words if name field is not empty email field should not be empty. Please let me know if some one can help me thank you.

<div class="leftCol">
        <label for="emailToName1" class="formLabel"><span class="required">*</span>Name:</label>
          <div><input type="text" id="emailToName1" name="referName01" value="${referAFriendBean.referName01!}" class="required" tabindex="1" /></div>
          <div class="pad5Top"><input type="text" id="emailToName2" name="referName02" value="${referAFriendBean.referName02!}" tabindex="3" /></div>
          <div class="pad5Top"><input type="text" id="emailToName3" name="referName03" value="${referAFriendBean.referName03!}" tabindex="5" /></div>
        </div>

        <div class="rightCol">
            <label for="emailToAddress1" class="formLabel"><span class="required">*</span>Email address:</label>
          <div><input type="text" id="emailToAddress1" name="referEmail01" value="${referAFriendBean.referEmail01!}" class="required email" tabindex="2" /></div>
          <div class="pad5Top"><input type="text" id="emailToAddress2" name="referEmail02" class="email" tabindex="4" value="${referAFriendBean.referEmail02!}" /></div>
          <div class="pad5Top"><input type="text" id="emailToAddress3" name="referEmail03" class="email" tabindex="6" value="${referAFriendBean.referEmail03!}" /></div>
        </div>
      </div>

1 Answer 1

1

Perhaps something like this:

if($('emailToName2').val() != '' && $('emailToAddress2').val() == ''){
//do something here
}

You could also check the length of each value.

if($('emailToName2').val().legnth > 0 && $('emailToAddress2').val().length == 0){
//do something here
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.