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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T13:12:42+00:00 2026-06-08T13:12:42+00:00

Hello I have a loop which renders elements within a partial view. The elements

  • 0

Hello I have a loop which renders elements within a partial view. The elements are listboxesfor, the number of listboxesfor rendered varies depending on a condition which is not accessible within the partial view itself. What I am trying to do is to find the number of listboxes rendered by using a javascript function and possibly the first listbox and then i could loop through them. another way to do is to assign a class name and then count but i cant do that. please help.

function dosomething() {
            var x = document.getElementsByTagName("listbox");//This line always returns O 
            alert(x.length);
}

 @Html.ListBoxFor(model => model.ServiceTypes, new MultiSelectList(RunLog.Domain.Lists.GlobalList.PartsServiceTypes(), "ID", "Name"), new { style = "width: 200px; height: 80px;", id = "lstbox", name="listbox", onclick = "dosomething()" })
  • 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-08T13:12:44+00:00Added an answer on June 8, 2026 at 1:12 pm

    There’s no such thing as listbox in HTML. It simply doesn’t exist. In HTML terms (which is what you are manipulating wit hjavascript) the element is called select with the multiple="multiple" attribute allowing multiple selection.

    So:

    var x = document.getElementsByTagName("select");
    // now when looping over this x variable make sure
    // you check for the presence of the multiple="multiple"
    // attribute which is the only thing which distinguishes
    // what you call a ListBox from a DropDown.
    for (var i = 0; i < x.length; i++)​ {
        var element = x[i];
        // I am not even sure if this is a good test for the presence
        // of the multiple attribute. Maybe it should work but can't guarantee
        // cross browser correctness
        if (element.multiple) {
            // we've got a list box here
        }
    }
    

    And if you decide to use jQuery:

    var listBoxes = $('select[multiple]');
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hello I have a loop which goes counts different records in my MySQL database
I have written simple first stage bootloader which displays Hello world using interrupt to
Hello Folks, I have a list which has values from a query. The list
i have an xml i load within my air app which looks like this:
Hello I have like this 2 tables class User public int UserId{get;set;} { ....
Hello i have 2 arrays and and i want to put them in a
Hello I have next function, what always return null as result, but service calling
hello i have this question i was trying to find a way to call
hello I have my code that connects to my ftp server $conn_id = ftp_connect($ftp_server);
Hello I have a UISegmentedControl with two segments. The selected segment is modified programmatically

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.