Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6962893
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T15:43:08+00:00 2026-05-27T15:43:08+00:00

I am using the following code: $.each($(‘.friendName’), function(){ if($(this).val() != ”){ var idName =

  • 0

I am using the following code:

$.each($('.friendName'), function(){
    if($(this).val() != ''){
        var idName = $(this).attr('id');
        var name = $(this).val();
        var email =  $('#' + idName + ' ~ input').first().val();
        alert(email);
    }
});

This code should go through each element with a class of friendName (3 input boxes).

Ones that aren’t empty, I then want it to find the associated friendEmail input box. For example:

friendName1 - friendEmail1
friendName2 - friendEmail2
friendName3 - friendEmail3

This should only get results for items that contain details, if only friendName1 and friendEmail1 are filled out, it doesn’t count the rest of them.

For some reason, I can’t get it to get the value of the friendEmail input, I’m guessing because it is not a sibling.

Any help would be greatly appreciated, and if you could advance on my code so that it checks to see if each friendName and friendEmail contain values, then returns them as var name and var email, that’d be great.

<div>
    <label for="friendName1">Friend's Name</label>
    <input type="text" id="friendName1" name="friendName1" class="friendName" value="" />
</div>

<div>
    <label for="friendEmail1">Friend's Email</label>
    <input type="text" id="friendEmail1" name="friendEmail1" value="" />
</div>

<div>
    <label for="friendName2">Friend's Name</label>
    <input type="text" id="friendName2" name="friendName2" class="friendName" value="" />
</div>

<div>
    <label for="friendEmail2">Friend's Email</label>
    <input type="text" id="friendEmail2" name="friendEmail2" class="friendEmail" value="" />
</div>

<div>
    <label for="friendName3">Friend's Name</label>
    <input type="text" id="friendName3" name="friendName3" class="friendName" value="" />
</div>

<div>
    <label for="friendEmail3">Friend's Email</label>
    <input type="text" id="friendEmail3" name="friendEmail3" class="friendEmail" value="" />
</div>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T15:43:08+00:00Added an answer on May 27, 2026 at 3:43 pm

    I created a jsFiddle with an approach http://jsfiddle.net/a2kHt/2/

    $(function(){
        $(".friendName[value!='']").each(function(){
            var idEmail = 'friendEmail' + $(this).attr("id").replace('friendName','');
            if($("#"+idEmail+"[value!='']").length > 0){
                alert("Name: " + $(this).val() + " - Email: " + $("#"+idEmail).val());
            }
        })
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i am fetching data using following code _.each(cardIds, function(id){ var mdc = new MdlCard({cardId:
I'm parsing a XML using jQuery with the following code: function appendNav(xml) { $(xml).find(Nav).each(function()
i want to validate all inputs using class name i'm using following code $('#submitbutton').click(function()
I'm using the following code: $.each($dataObj, function(index, value) { $(index).html(value); }); Which of course
I'm currently using the following code to append a X link to each element
I am using following code in rowdatabound function. Protected Sub gvwMileStone_RowDataBound(ByVal sender As System.Object,
I'm using following code but cannot return data from MySQL. This is the output:
I open a pop-up window using following code in main.html function openwindow(url) { window.open(url,
I am using the following code to construct a queue of 10 queues, each
I am using following code to check whether a check box on my website

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.