wood burning stoves 2.0*
The moose likes HTML, CSS and JavaScript and the fly likes Is Null, Not an Object, or Not Defined Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Is Null, Not an Object, or Not Defined" Watch "Is Null, Not an Object, or Not Defined" New topic
Author

Is Null, Not an Object, or Not Defined

Natalie Kopple
Ranch Hand

Joined: May 06, 2003
Posts: 325
I downloaded the Firefox hoping that I would get a better description of the "page error" for my Javascript code; but, IE at least gave a clue. The Firefox gave none.

I have tried

1. document.sortKey.value="firstName";
2. document.forms[0].sortKey.value="firstName";
3. document.elements.sortKey.value="firstName";
4. document.form[0].elements.sortKey.value="firstName";

I keep getting those are null or not object type. I do have two forms in my page. But, the form that I am trying to submit is the first one of those two forms. Please help me to spot the problems.

Here is my code:
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41580
    
  54
Firefox is usually pretty good at flagging problems with JavaScript. Did you use the Tools -> JavaScript Console?

As to the code, more interesting than the source would be the resulting HTML. Then we could see which HTML elements get created, and which names/IDs they have.


Ping & DNS - my free Android networking tools app
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61066
    
  66

Yes, showing us the Struts server-side Struts source is pretty much useless for diagnosing client-side problems.

There are all kinds of Javascript tools available for Firefox. Look into Firebug.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
because:

document.FORMNAME.elementName.value

Eric
Natalie Kopple
Ranch Hand

Joined: May 06, 2003
Posts: 325
Thank to all for kind responses.

Follow your instruction, I have used the Firefox Javascript Console. I do have a better clue now. But, it is not enough for me figure out the problem.

I have tried:

document.forms[0].sortKey.value = "firstName";

and

document.FindUsersForm.sortKey.value = "firstName";

The Firefox Javascript Console indicated that both of the two statements above have no property. That is:

document.forms[0].sortKey has no properties.

and

document.FindUsersForm.sortKey has no properties;

I have triple checked my FindUsersForm. It defines String SortKey and String orderKey. Both of them have proper getter and setters.

I have also 'view source' of the displayed web page. But, if offers no clue because the clicking on the link does not work at all.

Thanks in advance.
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
forms[0] means you are using the first form on the page. You have multiple. So if the field is in the second form, it is not going to find it.

That error message is saying that it has no properties since I can not find the object.

Eric
Natalie Kopple
Ranch Hand

Joined: May 06, 2003
Posts: 325
Good point. It is the third form in my web page. Therefore, I tried:

document.forms[2].sortKey.value = "firstName";
document.forms[2}.submit();

But, I got the same message saying that document.forms[2].sortKey has no properties.

I have also tried:

document.forms[1].sortKey.value = "firstName";
document.forms[1}.submit();

and
document.forms[3].sortKey.value = "firstName";
document.forms[3}.submit();

Error messages are the same.
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
when you do a view source on the page does the names of your form elements change?

Does it work if you use a form name

document.forms["formName"].

or

document.formName.

Eric
Natalie Kopple
Ranch Hand

Joined: May 06, 2003
Posts: 325
The names of my form elements do not change when I do 'view source'.

I have tried both:

document.forms["FindUsersForm"].sortKey.value = "firstName"
document.forms["FindUsersForm"].submit();

and

document.FindUsersForm.sortKey.value = "firstName"
document.FindUsersForm.submit();

The error messages are the same: has no properties.
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

Can you post the source? Not the JSP but the source you get with View Source on the browser?


GenRocket - Experts at Building Test Data
Natalie Kopple
Ranch Hand

Joined: May 06, 2003
Posts: 325
Thanks to all for your continuing and strong support. I really appreciate your help. I am simply working on what clients want to have in the web page although I do not quite agree on the page design.

The error message given by the Firefox has been identified. The error message means that I have to specify the 'sortKey' and 'orderKey' as properties inside the <html:form ....> tag.

Because I have multiple forms in my web page, I have also given an ID to the form that I intend to use the Javascript to submit.

But, while the values entered in text fields inside the form get submitted when any of the links are clicked, the constants for the sortKey and orderKey defined inside the Javascript using those "if" statements do "not" get submitted when the corresponding link is clicked. Therefore, there are still problems with the Javascript. I wonder if you could help in spotting my mistake(s).

Here is the code:


[ July 25, 2006: Message edited by: Natalie Kopple ]

[ July 25, 2006: Message edited by: Natalie Kopple ]

[ July 25, 2006: Message edited by: Natalie Kopple ]
[ July 25, 2006: Message edited by: Natalie Kopple ]
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
well if you use an ID you need to use getElementById().

Also you need to make sure that your element names are correct.

Eric
 
wood burning stoves
 
subject: Is Null, Not an Object, or Not Defined