File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes HTML, CSS and JavaScript and the fly likes Getting elements by id Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Getting elements by id" Watch "Getting elements by id" New topic
Author

Getting elements by id

Rakesh Keerthi
Ranch Hand

Joined: Jul 16, 2012
Posts: 136
Thanks for the hint Marc i've solved it. thank you once again i got a problem, i want to use this ID in my js as document.getElementbyId(), here what should i take in the braces.

Thanks
Marc Peabody
pie sneak
Sheriff

Joined: Feb 05, 2003
Posts: 4727

You can make the id attribute the same as the name attribute.

What have you tried so far?


A good workman is known by his tools.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60050
    
  65

Marc Peabody wrote:You can make the id attribute the same as the name attribute.

But this does not always work because names are not unique. id values must be.

In the future, please start new topics for new questions. I've split this one off form the original topic and moved it to a more appropriate forum.

You also need to spell getElementById() correctly.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Rakesh Keerthi
Ranch Hand

Joined: Jul 16, 2012
Posts: 136
Thank you bear for moving it to a new topic.
Marc i tried document.getElementById("temp")( this is wrong as i took id in input type as <input type="button" value="Update Answer" name="<%=temp2%>" id="temp2<%=i%>"> here i is taken from iteration). please suggest how do i approach with it.

Thanks
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60050
    
  65

id="temp2<%=i%>

What does this end up as at the browser? Do a View Source to see. Posting the JSP markup is not useful for dealing with client-side issues.

Whatever the actual id value is, is what you need to use.

P.S. Why are you still using scriptlets in 2012? That's technology that has been obsolete for over 10 years! See this JspFaq entry.
Rakesh Keerthi
Ranch Hand

Joined: Jul 16, 2012
Posts: 136
hi bear,
sorry for delay in my reply in the browser it shows id="temp12"(here i is used for a loop) and the source screen is as below.
i want this id to be used in java script, but i'm not knowing how to do it.

Thanks


[Thumbnail for Src.JPG]

Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
Post the code, not a photo it.

You are acting like x is a DOM node, when it is a string.
Rakesh Keerthi
Ranch Hand

Joined: Jul 16, 2012
Posts: 136
Hi Eric,
below is the code.

Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
Rakesh Keerthi wrote:Hi Eric,
below is the code.


And my answer above is still the same.

Rakesh Keerthi
Ranch Hand

Joined: Jul 16, 2012
Posts: 136
Hi Eric,

i did not get you. i'm not understanding what you are saying. DOM and String. If you dont mind, could you please let me know it briefly, i'll solve it myself.

Thanks
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60050
    
  65

In other words, if you are trying to grab the element, why are you using .value?
Rakesh Keerthi
Ranch Hand

Joined: Jul 16, 2012
Posts: 136
Ok thankyou Bear and Eric for the answer, but how do i get the value of the following input in document.getElementById();



what should i use for getting document.getElementById("temp2<%=i%>"); .
It is not accepted in js.

How do i get it?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60050
    
  65

what should i use for getting document.getElementById("temp2<%=i%>"); .

Again, what does that turn into on the browser? The JSP source is uninteresting and irrelevant.

It is not accepted in js.

Please read ItDoesntWorkIsUseless

How do i get it?

If the id passed to the getElementById is valid, it will work.
Rakesh Keerthi
Ranch Hand

Joined: Jul 16, 2012
Posts: 136
Hi Bear and Eric,

I'm unable to get what should be sent here. please give me a hint i'll solve it. i don't need the solution.

Thanks
Rakesh Keerthi
Ranch Hand

Joined: Jul 16, 2012
Posts: 136
i tried to move javascript to the body part and the result source code is as below.




here it is showing everything correctly corresponding to the button. but the button action is not happening.
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
Your html markup is invalid
Rakesh Keerthi
Ranch Hand

Joined: Jul 16, 2012
Posts: 136
Hi Eric,

i have removed <!DOCTYPE html>, but still the same problem. button action not getting triggered.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60050
    
  65

Rakesh Keerthi wrote:
i have removed <!DOCTYPE html>

What does that help? if your HTML is invalid, removing the DOCTYPE directive isn't going to make it any more valid.

Validate your HTML and fix the problems with it.

Search for "HTML Validator" for online validation tools.
Rakesh Keerthi
Ranch Hand

Joined: Jul 16, 2012
Posts: 136
Hi Bear,
i have validated my code using a html validator and changed the below highlighted code. It is giving 0 errors and 0 warnings . but the problem is not solved.

Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60050
    
  65

JSP markup is irrelevant to client-side problems.
Rakesh Keerthi
Ranch Hand

Joined: Jul 16, 2012
Posts: 136
But Bear, when i view the source in the browser everything is showing fine and as expected. where am i going wrong?
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
It has nothing to do with the doc type. A form is not a child element of a table. It can not wrap tr elements.

Eric
Rakesh Keerthi
Ranch Hand

Joined: Jul 16, 2012
Posts: 136
Eric, But , i think table can be a child of form. correct me if I'm wrong. and i added <table> inside a <form>, but still i don't see any difference.
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
Look at your code, you are writing tons of functions with the same exact name. Does Java or any other langauge let you do that? No. The funcitons override each other. You really need to figure out a new way of doing this. What you have done is bad.

Eric
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Getting elements by id
 
Similar Threads
javascript array object to parameter
Data: Unexpected database access problem
change language English French label
Use sequence or select max(field) from table to get next id?
Transaction isolation level