• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Javascript Error

 
Ranch Hand
Posts: 238
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Marshal
Posts: 67420
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Bartender
Posts: 1845
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 238
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Marshal
Posts: 67420
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you read Stefan's reply?
 
Muhammad Imad Qureshi
Ranch Hand
Posts: 238
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Marshal
Posts: 67420
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 238
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Marshal
Posts: 67420
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 238
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Marshal
Posts: 67420
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Create symphonies in seed and soil. For this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic