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

  • Home
  • SEARCH
  • 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 6101595
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T13:31:03+00:00 2026-05-23T13:31:03+00:00

I am working on a project where I need to use array values in

  • 0

I am working on a project where I need to use array values in the getElementById() in javascript.
I tried various things, but the code isn’t working.
Please help me.

I have an array of values like this:

 var examStateArr=["examState1","examState2","examState3","examState4","examState5","examState6","examState7"];

and i use it in getElementById() as:

document.getElementById(examStateArr[str1-1]).value.innerHTML=xmlHttp.responseText

But this doesnt work.

The code works just fine when I hard code values like document.getElementById("examState1"); but not when i use the array.

str1 is an integer that I pass from a jsp file below:

<%for (int j = 1; j < 8; j++) {%>
<tr>
<select  name='examCountry<%= j%>' onchange=showExamState(<%= j%>,this.value);>  
<option value="none" selected="selected">SELECT</option>
<% for (i = 0; i < countrySize; i++) {%>
<% country = (String) countryArr.get(i);%>
<option  value=<%= country%>><%= country%></option>
<% }%>
</select> 


</td>
<td id='examState<%= j%>'>
<select name='examState<%= j%>'>  
<option value='none'>Select</option>
</select>
</td>

Please correct my mistake.

Thank you in advance.

  • 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-23T13:31:03+00:00Added an answer on May 23, 2026 at 1:31 pm
    var examStateArr = ["examState1", "examState2", "examState3", "examState4", "examState5", "examState6"];
    
    for (var i = 0; i < examStateArr.length; i++) {
        document.getElementById(examStateArr[i]).innerHTML = xmlHttp.responseText   
    }
    

    Mistake one done by you

    document.getElementById('').value.innerHTML   -- is wrong
    document.getElementById('').innerHTML         -- is correct
    

    Edit 2

    make sure you call this function after DOM is loaded, try adding your script at the bottom

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

Sidebar

Related Questions

I'm working on a project where we use Hibernate and JBoss 5.1. We need
When working with Project Euler problems I often need large (> 10**7) bit array's.
I'm working on a project where I need to use a joystick (DirectInput) to
I am working a project where I need to generate a series of classes
I'm working on a project were we need more performance. Over time we've continued
I'm working on a project where I need the following. WCF service on the
I am working on a project where I need to create a boundary around
I am working on a project where I need to deal at the byte
I am working on a project and I need to save user configuration. The
I am working on this project where I need to read in a lot

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.