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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T00:14:31+00:00 2026-05-30T00:14:31+00:00

I have 5 list boxes with the same name. If i choose the same

  • 0

I have 5 list boxes with the same name. If i choose the same element in the list box it returns the error message as this value already selected. How to implement this in javascript Or in jquery

                <table width="50%" border="0">
            <tr>
            <td><select id="prev" name="prev[0][]" >
            <option value="test">test</option>
            <option value="test1">test</option>
            <option value="test2">test</option>
            <option value="test3">test</option>
            <option value="test4">test</option>

            </select>
            </td>
            </tr>
            <tr>
            <td><select id="prev" name="prev[0][]" >
            <option value="test">test</option>
            <option value="test1">test</option>
            <option value="test2">test</option>
            <option value="test3">test</option>
            <option value="test4">test</option>

            </select>
            </td>
            </tr>
            <tr>
            <td><select id="prev" name="prev[0][]" >
            <option value="test">test</option>
            <option value="test1">test</option>
            <option value="test2">test</option>
            <option value="test3">test</option>
            <option value="test4">test</option>

            </select>
            </td>
            </tr>
            <tr>
            <td><select id="prev" name="prev[0][]" >
            <option value="test">test</option>
            <option value="test1">test</option>
            <option value="test2">test</option>
            <option value="test3">test</option>
            <option value="test4">test</option>

            </select>
            </td>
            </tr>
            <tr>
            <td><select id="prev" name="prev[0][]" >
            <option value="test">test</option>
            <option value="test1">test</option>
            <option value="test2">test</option>
            <option value="test3">test</option>
            <option value="test4">test</option>

            </select>
            </td>
            </tr>
            </table>

The Query Function i used to check the listbox is selected or not is :

$("select[name^='prev["+k+"']").each(function( i ) {
        lsval = this.value;

        if(lsval == '') {
                alert("enter value");
                $("select[name^='prev["+k+"']").eq(i).focus();
                return false;
        }

    });

I have the options as (test,test1,test2,test3,test4)
If i choose the same value in more than 1 list box then it returns the alert message as (‘This value already selected’).

How to implement this. please do the needful. Thanks

  • 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-30T00:14:32+00:00Added an answer on May 30, 2026 at 12:14 am

    Hope this can help you but personally i believe alert on every selection is quite annoying
    HTML PART

                 <table width="50%" border="0">
            <tr>
            <td><select class="prev" name="prev[0][]" >
            <option value="test">test</option>
            <option value="test1">test 1</option>
            <option value="test2">test 2</option>
            <option value="test3">test 3</option>
            <option value="test4">test 4</option>
    
            </select>
            </td>
            </tr>
            <tr>
            <td><select class="prev" name="prev[0][]" >
            <option value="test">test</option>
            <option value="test1">test 1</option>
            <option value="test2">test 2</option>
            <option value="test3">test 3</option>
            <option value="test4">test 4</option>
    
            </select>
            </td>
            </tr>
            <tr>
            <td><select class="prev" name="prev[0][]" >
            <option value="test">test</option>
            <option value="test1">test 1</option>
            <option value="test2">test 2</option>
            <option value="test3">test 3</option>
            <option value="test4">test 4</option>
    
            </select>
            </td>
            </tr>
            <tr>
            <td><select class="prev" name="prev[0][]" >
            <option value="test">test</option>
            <option value="test1">test 1</option>
            <option value="test2">test 2</option>
            <option value="test3">test 3</option>
            <option value="test4">test 4</option>
    
            </select>
            </td>
            </tr>
            <tr>
            <td><select class="prev" name="prev[0][]" >
            <option value="test">test</option>
            <option value="test1">test 1</option>
            <option value="test2">test 2</option>
            <option value="test3">test 3</option>
            <option value="test4">test 4</option>
    
            </select>
            </td>
            </tr>
            </table>
    

    JQUERY PART

            $(function(){
            var PrevArray = [];
            $('.prev').live("click",function(){
                var selected = $(this).val();
    
                if($.inArray(selected,PrevArray) !== -1)
                {
                    alert('Already Selected');
                }
                else
                {
                    PrevArray.push(selected);
                    console.log(PrevArray);
                }
            });
        });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a list of check boxes. For the check boxes that are selected,
I have a list of file input boxes and I want to know if
I have a simple list view with some check boxes in an alert dialog.
I have a form with a list of people with check boxes next to
I have 4 List Boxes in my WPF App. Each of them, at any
Basically my dilemma is this. I have a list of x servers that host
I have 3 list boxes. I am splitting a text file to sort the
In my form, I have multiple fields (hidden text boxes) which has the same
I have a form in ExtJS, with 2 dropdown boxes with a list of
I have two list boxes with one to one mapping. They are also scrollable.

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.