473,508 Members | 2,412 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

extremely strange behavor, not able to retrive an form through getElementById

This is really very stange. I have a form like this:

<form id="form_A"> xxxx </form>

This form is on one page in a page of a web application, it is the only
form on that page. on the end of the page in javascript:
document.getElementById("form_A").submit();

In the begining it works very well, after I restarted the browser and
did some small modification (I don't recall, but far from chaning that
form or script), it doesn't work. After some debuging it shows
document.getElementById("form_A") gets nothing, element with this ID
does not exist.

I tried so many debugging:
1) if change <form id="form_A"> to <div id="form_A"> then
document.getElementById("form_A") works
2) if move <form id="form_A"> to just below <body> then
document.getElementById("form_A") works
3) if move <form id="form_A"> to just above </body> then
document.getElementById("form_A") return nothing
4) if move <form id="form_A"> to random place in the webpage
document.getElementById("form_A") return nothing
5) if remove all other javascript on that page, only have the HTML and
one line of javascript document.getElementById("form_A"), except if we
put the form just below <body>, otherwise
document.getElementById("form_A") return nothing
6) use HTMLTIDY it shows only warning but no error

all above are tested on mozilla 1.7.8, I picked up random cases to test
on Opera 8.0 Final, same behavor as on moz.

in all above case, if document.getElementById("form_A") return nothing,
other means to retrive the <form> element all failed. Including
* addresssing the form by "name" attribute;
* getElementsByTagName('form');
* alert(fatherelement.innerHTML).
It just vanishes perfectly! E.g if I display html.innerHTML then in the
dialogue box the whole HTML source is displayed, PERFECTLY without the
<form>

Any idea about why? I suppose javascript might be the
most-difficult-to-debug language on the earth. To really dig out the
reason of this strange behavor I must put <form> right above </body> and
remove other elements in the HTML source, once a half, and find out when
this behavor change. Such debuging would consume me A LOT of time.

I do program in many other languages, and I'd like to say javascript is
one of the most difficult to manage..
Jul 23 '05 #1
4 1812

Zhang Weiwu wrote:
all above are tested on mozilla 1.7.8, I picked up random cases to test
on Opera 8.0 Final, same behavor as on moz.


Post a URL to a test case which exhibits the problem. Run the document
through the validator http://validator.w3.org/ first.

--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 23 '05 #2
Zhang Weiwu wrote:
This is really very stange. I have a form like this:

<form id="form_A"> xxxx </form>

This form is on one page in a page of a web application, it is the only
form on that page. on the end of the page in javascript:
document.getElementById("form_A").submit();

In the begining it works very well, after I restarted the browser and
did some small modification (I don't recall, but far from chaning that
form or script), it doesn't work. After some debuging it shows
document.getElementById("form_A") gets nothing, element with this ID
does not exist.

I tried so many debugging:
1) if change <form id="form_A"> to <div id="form_A"> then
document.getElementById("form_A") works
2) if move <form id="form_A"> to just below <body> then
document.getElementById("form_A") works
3) if move <form id="form_A"> to just above </body> then
document.getElementById("form_A") return nothing
4) if move <form id="form_A"> to random place in the webpage
document.getElementById("form_A") return nothing
5) if remove all other javascript on that page, only have the HTML and
one line of javascript document.getElementById("form_A"), except if we
put the form just below <body>, otherwise
document.getElementById("form_A") return nothing
6) use HTMLTIDY it shows only warning but no error

all above are tested on mozilla 1.7.8, I picked up random cases to test
on Opera 8.0 Final, same behavor as on moz.

in all above case, if document.getElementById("form_A") return nothing,
other means to retrive the <form> element all failed. Including
* addresssing the form by "name" attribute;
* getElementsByTagName('form');
* alert(fatherelement.innerHTML).
It just vanishes perfectly! E.g if I display html.innerHTML then in the
dialogue box the whole HTML source is displayed, PERFECTLY without the
<form>

Any idea about why? I suppose javascript might be the
most-difficult-to-debug language on the earth. To really dig out the
reason of this strange behavor I must put <form> right above </body> and
remove other elements in the HTML source, once a half, and find out when
this behavor change. Such debuging would consume me A LOT of time.

I do program in many other languages, and I'd like to say javascript is
one of the most difficult to manage..


I am going to faint!!

I wish to save this webpage to local computer to research carefully.
What happens? I watched source viewer and made sure this <form> is in
source. click 'save as', and save a local copy, then this <form>
vanishes in the local copy!

By the way, this is a very normal form, normal as it could be:
<form id="launch_help"
action="/Byron/help/"
method="post" target="help_content">
<input name="help_topic" type="hidden" value="bookmarks"/>
</form>
Jul 23 '05 #3
Zhang Weiwu wrote:
Zhang Weiwu wrote:
This is really very stange. I have a form like this:

<form id="form_A"> xxxx </form>
[...]In the begining it works very well, after I restarted the browser and
did some small modification (I don't recall, but far from chaning that
form or script), it doesn't work. After some debuging it shows
document.getElementById("form_A") gets nothing, element with this ID
does not exist.

[...]

The symptoms indicate that the browser has not finished creating your
form when you call getElementById so the browser returns an error. Run
your script from <body onload="..."> and you may have more luck.

A debug step is to put an alert in your script just before you call
getElementById - something like:

alert('about to call getElementById...');

The pause should give your browser time to finish the form before the
call is made.

--
Rob
Jul 23 '05 #4

Use the MS Script Editor included free with MS Office 2002 and above,
for debugging Internet Explorer (IE).

This subject is of great interest to many JS developers, as there is no
obvious, low cost way to do sophisticated debugging in
IE6 other than to use the debugger described below, which is horribly
documented otherwise. I feel debugging is an important aspect of
projecting the useability of the language and needs to be made more
clear for new users.
Jeff Papineau
yo**@mandala.com
<FAQENTRY>

This is a page that describes how to install and use the MS Script
Editor to debug Javascript in Internet Explorer ( IE ). It has a
powerful debugger built into it that works really well for developers
supporting IE5+. This debugger/editor included with most versions of
Microsoft Office.

http://www.mandala.com/javascript/debug_javascript.html

..NET programmers may have better tools (VStudio) but this comes in
really handy for anyone developing with JSP and PHP and other dynamic
scripting languages which embed javascript, as well as any HTML page
using Javascript in Internet Explorer that needs a (almost) free
debugging environment.

</FAQENTRY>

Zhang Weiwu wrote:
Any idea about why? I suppose javascript might be the
most-difficult-to-debug language on the earth. To really dig out the
reason of this strange behavor I must put <form> right above </body> and
remove other elements in the HTML source, once a half, and find out when
this behavor change. Such debuging would consume me A LOT of time.

I do program in many other languages, and I'd like to say javascript is
one of the most difficult to manage..


Jul 23 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1329
by: Ron | last post by:
Hi, I have a client side srcipt control that is giving me some very strange problems when my Master.Page is layed out using <DIV> tags for the UI layout. When it is layedout in a <TABLE> style...
2
1894
idsanjeev
by: idsanjeev | last post by:
hello how can retrive the input text after submit button pressed and report a error message. i wants to post topic and if any error message is occured then retrive the inputed text but it forget its...
1
2970
by: amritranjan | last post by:
How to retrive image file from MS access database and display this in another JSPpage -------------------------------------------------------------------------------- This is my Jsp code for...
5
1912
by: perhapscwk | last post by:
I want to use ajax, by selected the option box, retrieve data from a .xml file and fill in to the textbox. below is the html page <script src="selectcd.js"></script> <form> Select a CD:...
0
7135
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7410
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7067
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7505
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5650
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
3215
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3201
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1570
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
440
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.