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 8384693
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T17:28:13+00:00 2026-06-09T17:28:13+00:00

I have 7 dropdown with the class name=dd. and i have 7 textbox with

  • 0

I have 7 dropdown with the class name=”dd”. and i have 7 textbox with the class name =”tt”. each text box corresponds to each dropdown.
now, i have to check

if(dropdown value is equal to 1)
    text box can not be empty.

so to do this what i am doing:

function checkOpenHours() {
        if ($('.dd').val() == 1 && $('.tt').val() == "") {

                alert("Please select an opening hour.");
                return false;

        }
    }

and i am calling this function like

<asp:Button ID="btnSave" runat="server" Text="Update hour" Height="35px" 
        onclick="btnSave_Click" OnClientClick="return checkOpenHours()"/>

BUT The problem is, this only works for the first dropdown and textbox.
It does not work for the other 6 dropdown and textbox ..!!

what am i doing wrong?? any help?

  • 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-06-09T17:28:15+00:00Added an answer on June 9, 2026 at 5:28 pm

    The .val() method returns the value from the first element in the jQuery object.

    You could do this instead:

    function checkOpenHours() {
        var $dd = $('.dd'),
            $tt = $('.tt'),
            i;
    
        for (i = 0; i < $dd.length; i++) {
            if ($dd.eq(i).val() == 1 && $tt.eq(i).val() == "") {
                alert("Please select an opening hour.");
                return false;
            }
        }
    }
    

    What I’m doing there is first putting the result of $('.dd') and $('.tt') into variables, because although using $('.dd') and $('.tt') in the loop would work it would be inefficient because it would recreate them (complete with DOM access) on every iteration. Then I’m using the .eq() method to get the elements at the current i index.

    I’m using a standard for rather than a jQuery .each() because it makes it easy to return from the outer function.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have dropdown menu..which is dynamic.. How can get value of the last item
So I have a drop-down list and a text-box: <table> <tr> <td>Group Name: </td>
I have 3 dropdown lists. 1) Type 2) Duration 3) Class <select name=passenger_type_of_pass class=pass>
I have this dropdown. I need clone for my other dropdown lists: <select name=general>
I have a dropdown menu that pulls in text from a database column. The
I have a dropdown menu that I am using and can't quite get it
I have this class in my model: class ServiceCharge(models.Model): name = models.CharField(max_length=30) amount =
I have my class RoomType : Int32 Id String Name String ColorCode My viewmodel
Does anyone know how to get my class name and method name dropdown lists
Suppose I have a dropdown select option like below: <form> <select name=option > <option

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.