Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Reply
how to manipulate elements of multiple document from common js file
Old 12-01-2008, 02:59 AM how to manipulate elements of multiple document from common js file
Junior Talker

Posts: 2
Name: su mon wai
Trades: 0
Hi,

I'm a beginner in web app.
To cut it short, i'm having problem with handling elements from multiple documents.
The idea is multiple html pages calling a common js file, from only one document at a time. eg. when the search page calls the js file, it'll only handle the elements of that search.html.
I need to so a lot of element handling like
document.getElementById(
'mnuSearch').style.color = '#647782';
or
var input = document.getElementById('txtUserName').value;
It's working fine when there is only one document.
When there are more than 1 documents, the document.getElementById('mnuSearch') is not recognized.
That keeps giving "undefined".
How can I solve that?
Thanks

rgds,

tyml
Theyemalay is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 12-01-2008, 03:12 AM Re: how to manipulate elements of multiple document from common js file
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,528
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
If the elements don't exist on the page when you call the javascript they will be "undefined",

Set variables on the page to indicate which elements exist, and use logic to determine whether to set the properties for those elements.
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 12-01-2008, 03:20 AM Re: how to manipulate elements of multiple document from common js file
Junior Talker

Posts: 2
Name: su mon wai
Trades: 0
They do exist. When there is only one html page, it worked.
When I create some more html pages, the previously working functions are not working anymore.
>> var input = document.getElementById('txtUserName').value;
alert(input); << that will alert "undefined"
Theyemalay is offline
Reply With Quote
View Public Profile
 
Old 12-01-2008, 04:00 AM Re: how to manipulate elements of multiple document from common js file
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,528
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
sure, but do they exist on the current page.
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Reply     « Reply to how to manipulate elements of multiple document from common js file
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.13120 seconds with 12 queries