User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the JavaScript / DHTML / AJAX section within the Web Development category of DaniWeb, a massive community of 456,593 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,520 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our JavaScript / DHTML / AJAX advertiser: Lunarpages Web Hosting
Views: 1481 | Replies: 7
Reply
Join Date: May 2006
Posts: 58
Reputation: kaushik259106 is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 0
kaushik259106 kaushik259106 is offline Offline
Junior Poster in Training

Help Help regarding accessing HTML tag lib from JS

  #1  
Sep 8th, 2007
I use the following code to display the user name on the website.. like
"Welcome Kaushik"

<jsp:useBean id="adminUser" class="bss.BSSUserDetailsDo" scope="session"/>

<font size="4" color="brown" face="verdana">
<bean:message key="Bss.user.welcome"/> //comes from some property file  abcd.property
<jsp:getProperty name="adminUser" property="firstName"/>
</font>

i want to access the user first name from my JS function.
i tried
var name = document.getElementById('firstName');

but not able to access! any idea..
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Jun 2006
Location: India
Posts: 7,012
Reputation: ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold 
Rep Power: 25
Solved Threads: 368
Moderator
Featured Poster
~s.o.s~'s Avatar
~s.o.s~ ~s.o.s~ is offline Offline
Lazy, Useless & Apathetic

Re: Help regarding accessing HTML tag lib from JS

  #2  
Sep 8th, 2007
Put the text data in their own container tags. Also don't use <font> tags, they are deprecated in favor of stylesheets. Something like :

<jsp:useBean id="adminUser" class="bss.BSSUserDetailsDo" scope="session"/>
<div style='font: normal 12px verdana; color: brown;'>
<bean:message key="Bss.user.welcome"/>
<span id='firstName'><jsp:getProperty name="adminUser" property="firstName"/></span>
</div>

You were erroneously using the bean property 'firstName' to access the element of the DOM. You have got to realize that the server side constructs you are using have got nothing to do with the generated text. The user only gets the processed JSP file.
I don't accept change. I don't deserve to live.

Happiness corrupts people.

Failing to value the lives of others cheapens your own.
Reply With Quote  
Join Date: May 2006
Posts: 58
Reputation: kaushik259106 is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 0
kaushik259106 kaushik259106 is offline Offline
Junior Poster in Training

Re: Help regarding accessing HTML tag lib from JS

  #3  
Sep 10th, 2007
thanx for your response S.O.S.. i have made the changes as you told.
now when i try to access it and display on my page using " name.value " it displays "undefined". What i might have done wrong??

i saw my page source code after executing the page.. the source is some thing like this
<div style='font: normal 12px verdana; color: brown;'>
Welcome
<span id="firstName">
Tommy 
</span>
</div>

where Tommy is the name i want to acces.Do you think its correct?
Reply With Quote  
Join Date: May 2006
Posts: 58
Reputation: kaushik259106 is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 0
kaushik259106 kaushik259106 is offline Offline
Junior Poster in Training

Re: Help regarding accessing HTML tag lib from JS

  #4  
Sep 10th, 2007
hay another thing..

this is a new thing which came with the change..

i made a function such that if the user types the same name as "Tommy" it should execute.
And the funny thing is as soon as i press "t" or "T" it gets executed.
Reply With Quote  
Join Date: May 2006
Posts: 58
Reputation: kaushik259106 is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 0
kaushik259106 kaushik259106 is offline Offline
Junior Poster in Training

Re: Help regarding accessing HTML tag lib from JS

  #5  
Sep 10th, 2007
friend while i was trying i found the following code also give the same problem.. why is it so. If the code below works then my problem will be solved!

<html>
<body>

<h1 id="header">My header</h1>

<script type="text/javascript">
document.getElementById('header').style.color="red"
var a = document.getElementById('header');
document.write(a.value);
</script>

<p><b>Note:</b> It is the script that changes the style of the element!</p>

</body>
</html>

i changed the code from http://www.w3schools.com/dhtml/tryit...html_dom_color
Last edited by kaushik259106 : Sep 10th, 2007 at 6:47 am. Reason: added some more info.
Reply With Quote  
Join Date: May 2006
Posts: 58
Reputation: kaushik259106 is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 0
kaushik259106 kaushik259106 is offline Offline
Junior Poster in Training

Re: Help regarding accessing HTML tag lib from JS

  #6  
Sep 10th, 2007
Friend i was able to solve my problem using JSP within JS but i will wait for the answer ! I want to learn!
ThanX
Reply With Quote  
Join Date: Jun 2006
Location: India
Posts: 7,012
Reputation: ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold 
Rep Power: 25
Solved Threads: 368
Moderator
Featured Poster
~s.o.s~'s Avatar
~s.o.s~ ~s.o.s~ is offline Offline
Lazy, Useless & Apathetic

Re: Help regarding accessing HTML tag lib from JS

  #7  
Sep 10th, 2007
<div style='font: normal 12px verdana; color: brown;'>
Welcome<span id="firstName">Tommy</span>
</div>
Access the contents of non-form elements(span and div) using the 'innerHTML' property. Something like document.getElementById('firstName').innerHTML

> And the funny thing is as soon as i press "t" or "T" it gets executed.
You need to show me the event handling code.

> var a = document.getElementById('header');
> document.write(a.value);
Again the same mistake. Access the inner HTML of a non-form element using the 'innerHTML' property. Something like alert(a.innerHTML).
I don't accept change. I don't deserve to live.

Happiness corrupts people.

Failing to value the lives of others cheapens your own.
Reply With Quote  
Join Date: May 2006
Posts: 58
Reputation: kaushik259106 is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 0
kaushik259106 kaushik259106 is offline Offline
Junior Poster in Training

Re: Help regarding accessing HTML tag lib from JS

  #8  
Sep 10th, 2007
ok.. i didnot knew this.. Thanx for your responses.. Let me try.thanx again
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb JavaScript / DHTML / AJAX Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the JavaScript / DHTML / AJAX Forum

All times are GMT -4. The time now is 6:47 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC