Click here to Skip to main content
15,918,471 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,

I am trying to get the value from a list box on page load. And the values in list box are populating from Java Script using XmlHttp Header.
From Ajax I am able to get Values in list box from server side but I am nor getting the list box value on page load.

Here is the code for xml Http header where the values are updated in list box from response :

var customerList = document.getElementById("ListBox");
for (var count = customerList.options.length-1; count > -1; count--)
{
    customerList.options[count] = null;
}

var customerNodes = customerNode.getElementsByTagName('customer_name');
var textValue;
var optionItem;
for (var count = 0; count < customerNodes.length; count++)
{
    textValue = GetInnerText(customerNodes[count]);
    optionItem = new Option( textValue, textValue, false, false);
    customerList.options.add(optionItem);
}

Please help me in resolving my problem. Thanks in advacne !
Regards,
Divya
Posted
Updated 24-Jan-10 1:06am
v2

Try something like this:

JavaScript
var typeElem = responseElem[0].getElementsByTagName("Table");       
for (var i = 0; i <typeElem.length;i++)
 {
          var textNode = document.createTextNode(typeElem[i].firstChild.text);
         AppendToSelect(typeElem[i].lastChild.text, textNode);
 }

function AppendToSelect(value, content)
{   
    var opt;
    customerList = window.document.getElementById("ListBox");     
    opt = document.createElement("option");        
    opt.value = value;     
    opt.appendChild(content);    
    customerList.appendChild(opt);
}


You should be able to get the values selected during postback.
 
Share this answer
 
v3
Hi,

Thanks for your response but I am still not able to get the values from list box at page load and it gives error stating "Object set to null reference".

Regards,
DIvya
 
Share this answer
 
I got the solution :

http://forums.devshed.com/net-development-87/problem-with-a-listbox-populated-from-javascript-184068.html

This Worked for me ! :)

Thanks for your time.

Regards,
Divya
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900