Dealing with empty properties
Hello all,
I am working with ASP.NET 2.0 and am fluent in C#. I am, however, learning javascript. I am starting ot see in a postback heavy environment like asp.net that javascript is a little more difficult, especially if you are trying to hold variables hehe. The issue I am having is upon page load, most elements are empty. Prime example is make a list control with nothing selected selected by default and try to do a comparison with it in an if statement..example:
I have an asp.net list box call "lstTest" containing 2 items in its collection..."This and "Other".
I have a textbox called "txtOther".
I want textbox to always be hidden but show up when other is selected in lstTest so here is what I write. the "lstTest" control has an onChange event appended in it that looks something like this:
onChange="Tests('lstTest');"
As you can see, stuff is going to equal "lstTest".
function Tests(stuff)
{
var myIndex = document.getElementById(stuff).selectedIndex;
var myValue = document.getElementById(stuff)[myIndex].value;
if (myValue != "Other")
document.getElementById("txtOther").style.visibili ty = "visible";
else
document.getElementById("txtOther").style.visibili ty = "hidden";
}
Problem I am getting is when the page is first loaded from a refresh or any form of postback, the visibility property is empty and in java I do not know how to test against an empty property unlike in C# there is always a value, even if it is null unless the object doesn't exist at all.
|