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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T08:12:22+00:00 2026-06-04T08:12:22+00:00

Below, I have a java script function (named stateChange) which is expected to update

  • 0

Below, I have a java script function (named stateChange) which is expected to update the content of an HTML selection list (Please see the code section marked as HERE below). I have verified that the server returns the new data properly by writing some alert statements (i.e. xmlHttp.onreadystatechange=function() { alert(xmlHttp.responseText); }).

Based on these alert statements in the function, I noticed that the line

      document.getElementById("dgpids").innerHTML=xmlHttp.responseText;  

is not executed at all, so the page is not updated with the new data from the server.

Can someone tell me what I am missing here in the function stateChange below? Why do you think the page is not updated with new data? Thanks.

     <%@page import="java.util.List"%>
     <%@page import="com.pm.dao.VirtualConfigTableDAO;" %>
     <%@page import="com.pm.entity.VirtualConfigEntity;" %>
     <%@page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
   <!DOCTYPE html>
   <html>
   <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>DAE PM Counters</title>

    <script language="javascript" type="text/javascript">  
        var xmlHttp              
        function stateChange(){                                  
            if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){   
                **//!!!!!! HERE !!!!!**
                //FOLLOWING LINE works                    
                xmlHttp.onreadystatechange=function() { alert(xmlHttp.responseText); }
                //I cannot update the list named dgpids below.
                //The content of the response text coming from the server is correct.
                //But the following line does not update the page. Do you know why???
                document.getElementById("dgpids").innerHTML=xmlHttp.responseText;   

                xmlHttp.onreadystatechange=function() { alert('Got here2!'); }                                       
            }                                  
        }

        function showState(str){
            if (typeof XMLHttpRequest != "undefined"){
                xmlHttp= new XMLHttpRequest();
            }
            else if (window.ActiveXObject){
                xmlHttp= new ActiveXObject("Microsoft.XMLHTTP");
            }
            if (xmlHttp==null){
                alert("Browser does not support XMLHTTP Request")
                return;
            } 
            var url="dgp.jsp";
            url +="?id=" +str;
            xmlHttp.onreadystatechange = stateChange;
            xmlHttp.open("GET", url, true);
            xmlHttp.send(null);
        }


    </script> 

</head>
<body>
    <form method="POST" name="me">
        <select size="13" name="D1"  multiple="no" onChange="checkData()">             
            <option value="1">CommonCounters(vDaeId)</option>
            <option value="2">DgpCommonCounters(dgpId, vDaeId)</option>
            <option value="3">SystemCommonCounters()</option>
        </select>
        <input type="submit" value="Submit" name="B1">
        <input type="reset" value="Reset" name="B2"></p>        
        <br/>

        <%
            VirtualConfigTableDAO dao = new VirtualConfigTableDAO();
            List<VirtualConfigEntity> vList = dao.getEntireVirtualConfigList();
        %>

        <select size="2" name="D2"  multiple="no" onChange="if (this.selectedIndex != -1) showState(this.value);" onclick="showState(this.value);">   
            <%
                for (VirtualConfigEntity entity : vList) {
            %>                              
            <option value="<%=String.valueOf(entity.getId())%>"> <%=String.valueOf(entity.getVirtualId())%></option>
            <%}%> 
        </select>


        <br/>
        <br/>
        <select name="dgpids" >  
            <option value='-1'></option>  
        </select>


    </form>
</body>

  • 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-04T08:12:24+00:00Added an answer on June 4, 2026 at 8:12 am

    You don’t have an element with an id of dgpids.

    I think you meant to give the select an id but I’m not sure a select would allow innerHTML. You may be better wrapping the select in a div and updating your server code to return the full select html which can be inserted into the div.

    Something like in this jsfiddle.

    Hope this helps.

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

Sidebar

Related Questions

I have Javascript as below: <script type="text/javascript" language="javascript"> function redirectToPrevious(abcURL) { window.location.replace(abcURL); } function
I have a java file Test.java (below) which uses Guava's HashMultiMap (downloaded from http://code.google.com/p/guava-libraries/
I have wrote the code below which was taken from Java How to program
I have added onfocus and onclick to select and written java script function as
In my HTML file, I have a JavaScript function named CheckCaptcha. I am using
I have the script below for a graphing system named flot, available to download.
I have JavaScript of ajax uploader as below; $(document).ready(function(){ var qwerty = $('#qwerty').val(); $('#demo1').ajaxupload({
I have a dialog box, created with the code javascript and HTML generated below.
So I have a java hashmap like below: hMap.put(1, One); hMap.put(2, Two); hMap.put(3, Two);
I have a simple code below: import java.util.ArrayList; public class BoidList extends ArrayList {

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.