Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Java > Java and JDK > Java Basics
| Search | Today's Posts | Mark Forums Read
Java Basics General beginning Java language questions that don't fit in one of the more specific forums. Please specify what version.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Java Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old January 19th, 2006, 08:03 PM
Authorized User
Points: 333, Level: 6
Points: 333, Level: 6 Points: 333, Level: 6 Points: 333, Level: 6
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2005
Location: Fresno, California, USA.
Posts: 94
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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.
  #2 (permalink)  
Old January 19th, 2006, 08:09 PM
Friend of Wrox
 
Join Date: Jan 2006
Location: San Francisco, CA, USA.
Posts: 198
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I'm having difficulties understanding your question, but have you tried putting onload="Tests('lstTest');" in your <body> tag? That should set the visibility of your txtOther field after refreshes and post backs.

Jon Emerson
Adobe Systems, Inc.
http://images.burningman.com/index.cgi?q_photog=emerson
  #3 (permalink)  
Old January 19th, 2006, 08:35 PM
Authorized User
Points: 333, Level: 6
Points: 333, Level: 6 Points: 333, Level: 6 Points: 333, Level: 6
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2005
Location: Fresno, California, USA.
Posts: 94
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by panacea
 I'm having difficulties understanding your question, but have you tried putting onload="Tests('lstTest');" in your <body> tag? That should set the visibility of your txtOther field after refreshes and post backs.

Jon Emerson
Adobe Systems, Inc.
http://www.jonemerson.net/
Yeah, that is already in there. The issue I am having is it is saying that the line that is checking to see what visibility is set to is actually undefined or not present. hence I get java script error on page load saying that the value is null or undefined. In otherwords, it is like I have to set it to test it but no way to check if it is null or undefined. I tried checking for the actually values of undefined and null but still get jscript error about the value being undefined. To give you an example. Make a list box with nothing selected on load and try to check to test the selected index in an if statement without selected an index in the list. It is an undefined box so conventional checking will give you an error. I looked online and saw articles on how to check for undefined and null but none of them seem to be working. I even tried just putting the document line by itself with no == after it so if it is null it will equate out to being false but if it has something it will equate out to be true but that test errors out with the same error. Is there a built in method to see if something is selected and if not the make my textbox invisible?

  #4 (permalink)  
Old January 21st, 2006, 04:31 PM
Friend of Wrox
 
Join Date: Jan 2006
Location: San Francisco, CA, USA.
Posts: 198
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Can you provide a concrete example including code?

I suspect that you're trying to access an attribute off of a undefined variable. For example, given "a.b.c.d", if "a.b.c" resolves to undefined, then you will get an error when trying to access a.b.c.d. So while you're going down the object hierarchy, make sure that each step of the way is defined.

Jon Emerson
http://www.jonemerson.net/
  #5 (permalink)  
Old June 5th, 2006, 08:03 PM
Authorized User
Points: 333, Level: 6
Points: 333, Level: 6 Points: 333, Level: 6 Points: 333, Level: 6
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2005
Location: Fresno, California, USA.
Posts: 94
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thought I should complete this thread. :) The actual issue I was having was I was accessing a control that was a list type control in ASP.NET but was turning into something else in html so the select property I was trying to access was not present. Changed to a different asp.net control that shows up the way I want in HTML and now everything works fine. I was trying to allieviate some server side postbacks that was not necessary just to check a property on a selection when it changes. Since that time, an Atlas CTP was released and now I can just use the updatepanel to get rid of the postback flicker.



Similar Threads
Thread Thread Starter Forum Replies Last Post
dealing with drop downs lisabb ASP.NET 2.0 Basics 5 May 28th, 2007 12:29 AM
Dealing with web.config richpopeye ADO.NET 1 August 31st, 2004 04:58 PM
ADOX MSDASQL Access Properties Collection is EMPTY Xentrax Access 0 May 27th, 2004 10:36 AM
Dealing with DBNull jaucourt VB.NET 2002/2003 Basics 3 January 16th, 2004 10:59 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.