Help answer threads with 0 replies.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
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.


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

Rep: Reputation: 30
accessing forms elements with javascript

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
function printElement(new_page) {
   object = new_page.document.getByElementById("textfield_id");

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


Old 06-03-2005, 02:46 PM   #2
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
Registered: Jun 2004
Location: PA
Distribution: Fedora (latest git kernel)
Posts: 458

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

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

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

happy hacking to you



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 > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:05 AM.

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