document.getElementById('lblName').value, returns blank

Dear All

I am facing a stupid problem. Actually on my form, there is a element (type= text). I am storing value in this element using Ajax.

syntax is : document.getElementById(‘lblName’).value=xmlHttpObj.responseText.

now on the same procedure I am getting value from this element. It returns blank. Why I don’t know.

I am doing this because Ajax statechaged() method does not return value. it always sows undefined.

Please help me out from this situation

Regards

Ashish

Subject: document.getElementById(‘lblName’).value, returns blank

If statechanged() never returns anything useful, your AJAX code is obviously not working as it should. What is expected to be in responseText? And what is actually returned? Use some JS debugger like Firebug to check your code.

And if you plan to use returnText again within the same function, why don’t you simply access it to a variable instead of trying to read it from the input again?

Subject: RE: document.getElementById(‘lblName’).value, returns blank

Dear Harkpabst Meliantrop

Thank you for your response.

My responseText returned the right value, what I am expecting. but when I store that value in a global variable, so that I can use it in another function that time value of that variable shows “Undefined”. that’s why I took another approach to do this. Instead of storing this value into a variable, I store it in a html element( type = text). and retrieving the value from that element. value displays in the html element but when I am trying to retrieve that value using document.getElementById(‘lblName’).value it gives blenk. I saw the view source of that page, then I found that value of that element is blank. if it is blank then why it is showing in the page. It’s really confusing. please do me help.

Thanks

Regards

Ashish

Subject: RE: document.getElementById(‘lblName’).value, returns blank

View->Source in IE (or View->Page Source in Mozilla) shows you the HTML source AS THE SERVER SENT IT. You’d need to look at the DOM tree or use the View Generated Source facility in the Firefox Web Developer Toolbar plug-in to see the changes that your code makes to the document.

Your statement that storing the value in a global variable later results in “undefined” makes no sense. If the variable isn’t available to the second function, then it’s not global. If you use the var keyword in the function that sets the value, then you aren’t using the same variable you have declared globally.

What kind of element are you storing the data in? If it’s an , does it have an id attribute with the value “lblName”? That is, does it look like this:

(Note that the type attribute defaults to text, so it’s not strictly necessary to include type=“text” in the tag.)

If “lblName” is not an element (or an , but I have no idea why anyone would use on of them for something like this), it doesn’t have a value attribute, so you’d need to use innerHTML or look at the child text nodes for a nodeValue.