Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Access a form element from a .JS file 1

Status
Not open for further replies.

thysonj

Programmer
Jul 6, 2001
240
US
Is there any way to access a form element from an included .js file? What I want to do is to get the client width from a particular element that is located on the opener page. I can do this using some JS on the opener page but I need to have it in the included js file and I can't seem to get it right! I am starting to think this is not possible.
 
I am not 100% certain without trying some tests, but if you can't access the form element from the function, then send the form element as a parameter TO the function.

e.g.,

<select onchange='callFunction(this);'>
...

...or:

<input type='button' onclick='callFunction(this.form.textFieldName);' />

'hope that helps.

--Dave
 
I am not using it as a function right now but I suppose I could implement it that way. To explain somewhat further...I am putting a news scroller on an intranet page. I have found various news scrollers that work just as I'd like except that they all end up being static interms of their width. This creates problems in that our user base will be using screen resolutions of anywhere from 640x480 to 1024x768. Id' like to be able to get the clientWidth of the parent table(on the opener page) and dynamically size the width. I am not even sure clientWidth will work since I believe it must load the entire page before resolving widths and such.
 
You actually got me on the right track and of course my suspicions were right and clientWidth will not worl :(. Anyone have any idea how to get a dynamically sized news scroller?
 
I didn't quite follow your whole description of your situation, but if you need the clientWidth, but can't get it until the page loads, then wait until the page loads to get it. In other words, use the BODY tag's ONLOAD event to request the clientWidth.

<BODY ONLOAD='startTicker(document.body.clientWidth);'>

...or whatever. So, even if your ticker is the wrong size when it first appears on the screen, you can adjust it when the page is finished loading.

Does that help?

--Dave
 
This and the other thread has helped immensely.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top