LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-03-2005, 11:26 AM   #1
djgerbavore
Member
 
Registered: Jun 2004
Location: PA
Distribution: Fedora (latest git kernel)
Posts: 458

Rep: Reputation: 30
accessing forms elements with javascript


hello,
i having alittle trouble with javascript. I'm trying to open a web page and access its form elements with document.getElementById("name_of_object"), however the object i get is always null.

here is my code
Code:
function printElement(new_page) {
   object = new_page.document.getByElementById("textfield_id");
   alert(object);
}

newWin = window.open("myphpfile.php", "", "width=600,height=600");
printElement(newWin);
everytime i run this, i get a null value in the alert box. Is there a way to do this.


thanks,

djgerbavor3
 
Old 06-03-2005, 02:46 PM   #2
huibert.alblas
Member
 
Registered: Jan 2004
Location: Duesseldorf /Germany
Distribution: Gentoo amd64 / Debian
Posts: 226

Rep: Reputation: 30
I think this is a timing problem.
You instruct the browser to open a new window, with a new page.
This method returns imidiatly, even before the document is fully loaded.
Thus as you execute printElement(newWin);
The document contains nothing (yet).

try to wait a few secs between the 2 calls.

To do it better: the called window should notify its caller when it is done loading. Than the parent wind should execute the next method.

This is a bit like the "AJAX" metholgie, wich is the latest and greatest new buzzword, just like DHTML was :-)

Happy hacking (and remeber: timing in Javascript is very odd)

(as a side note
AFAIK "object" is a reserved word (used like
"var testObject = new Object();"
or something like that)

Anyway, object is not a good name, do not use it.
 
Old 06-03-2005, 03:32 PM   #3
djgerbavore
Member
 
Registered: Jun 2004
Location: PA
Distribution: Fedora (latest git kernel)
Posts: 458

Original Poster
Rep: Reputation: 30
haha ya, it worked

Code:
function printFunction() {
    var obj = newWin.document.getElementById("form_element");
    obj.value = "whateverIwant";
}

newWin = window.open("myphpfile.php", "", "');
settimeout("printFunction()", 1000);
thanks alot!!!!

happy hacking to you


djgerbavor3
 
  


Reply


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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
javascript calls to embedded echo'd php forms xemous Programming 1 08-21-2005 07:29 AM
Text elements do not appear in Flash or SVG Baryonic Being Linux - Software 0 07-31-2005 02:29 PM
Why are some elements missing after using strcat() monil Programming 4 03-08-2005 08:40 AM
how to copy elemnts of two different structrue elements alix123 Programming 1 11-24-2004 11:12 AM
The Elements Of Style: UNIX As Literature m0rl0ck General 7 10-03-2003 06:03 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:28 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration