aspose file tools*
The moose likes JSP and the fly likes Javascript Error Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Javascript Error" Watch "Javascript Error" New topic
Author

Javascript Error

Muhammad Imad Qureshi
Ranch Hand

Joined: Sep 13, 2005
Posts: 238
I am getting following scripting error in my jsp

document.getElementById ("incident.incidentId") has no properties.

I am setting a property <html:hidden property="incident.incidentId" />
and then using it

Can Anyone please help. I m new in this field.
Thanks
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61658
    
  67

It looks like you are mixing metaphors.

If I understand what the <html:hidden property="incident.incidentId" /> tag does (and I am just guessing as it is not a standard tag), it creates a hidden input elment with a an initial value obtained from the incidentId property of the incident bean.

You'd have to check the generated HTML to be sure, but unless I'm missing my guess, you have done nothing to name the element in a way that can be referenced from Javascript.

Is there perhaps a name attribute on the tag that you can use?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Stefan Evans
Bartender

Joined: Jul 06, 2005
Posts: 1018
You can use the styleId attribute of html:hidden to specify an id attribute to be created with it.

<html:hidden property="incident.incidentId" styleId="myIncidentId"/>
and use:
document.getElementById ("myIncidentId")

You will probably find it easier if you don't use dots for the id.
Muhammad Imad Qureshi
Ranch Hand

Joined: Sep 13, 2005
Posts: 238
I am posting my actual code below. Can you loook at it and guess what is wrong. Thanks for your help so far. I have bold the lines where the problem is.

html:form action="incidents.do" method="post" styleId="trackerIncidents" onsubmit="return false;"
html:hidden property="incident.incidentId" /
html:hidden property="incident.latitude" /
html:hidden property="incident.longitude" /
input type="hidden" name="mapLoaded" id="mapLoaded" value=""/
html:hidden property="requestAction" styleId="requestAction" value="" /

script language="JavaScript" type="text/javascript"


if(document.getElementById("incident.incidentId").selectedIndex != 0) {
setElementValue('incidentID_label','no_modify',false,false);
setElementValue('incidentID','no_modify',false,false);
} else {
setElementValue('incidentID_label','no_modify',true,true);
setElementValue('incidentID','no_modify',true,true);
}

document.getElementById("incident.event.eventId").focus();
//--
/script
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61658
    
  67

Did you read Stefan's reply?
Muhammad Imad Qureshi
Ranch Hand

Joined: Sep 13, 2005
Posts: 238
I did and then I get error in one of my script files like this:

document.getElementById(_elementId) has no properties. in the following javascript code (.js file)

if(!_disabled) {document.getElementById(_elementid).disabled = false; document.getElementById(_elementid).style.backgroundColor = "";}

Is it because backgroundColor is set to an empty string ?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61658
    
  67

No, it's probably because your element does not have an id.

Take my suggestion from my first post and look at the generated HTML. Is there an id attribute on the element?
Muhammad Imad Qureshi
Ranch Hand

Joined: Sep 13, 2005
Posts: 238
Thanks Bibeault

You were right. the value of incident.incidentId was null. SoI have fixed it using if condition that if this value is null dont evaluate the next line. Now I get no scripting errors in Mozilla but in IE 6 I get same error that document.getElementById (....) is null or not an object on the following line of my .js file

if(!_disabled) {document.getElementById(_elementid).disabled = false; document.getElementById(_elementid).style.backgroundColor = "";}

I am sorrry I think its too much to ask but just in case if you ahve any clue why I am getting this.
Thanks for your help.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61658
    
  67

if you ahve any clue why I am getting this.


Yes, as I have said a few times: you cannot use getElementById to find an element that does not have an id.

You need to figure out how to get an id attribute onto the element. Stefan's post gave you one approach that may work.

In my opinion, your use of the Struts tags is obviously doing you a disservice in that they are obfuscating too much and preventing you from learning how web apps and web pages work. I would back out of the use of any such frameworks until you understand the basic concepts.
[ September 14, 2005: Message edited by: Bear Bibeault ]
Muhammad Imad Qureshi
Ranch Hand

Joined: Sep 13, 2005
Posts: 238
You are absolutely right. But I am at work and I am fixing someone else's code who is not even here any more. I am trying to improve my basic concepts after work by reading books and online articles.

Thanks for your help though. I am really glad to join this forum.
Imad
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61658
    
  67

In that case I'd grab the documentation for the tag set that you are using to find out how to make them do what you want. Looking at the rendered HTML using the browser's View Source mechanism can go a long way to help figure what's going wrong on the client side.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Javascript Error