473,756 Members | 1,842 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Opera bug? -- disappearing <form> ?!

[Submitted as a bug to Opera; posted here in hopes of finding an explanation?]

In Opera 8.01 (Linux; Build 1204) and in Opera 7.54 (Windows XP; Build 3865),
my form disappears from the HTML markup (below). To summarize:

1) In a <script> block in the <head> I create a form element (part of
object/feature/bug detection).
2) There's a <form> element defined in the <body>, with the id 'theForm'.
3) The onload function tries to access that form, and also counts the
total number of forms in the document. It fails to get a reference
to the form; the count is 0.

Black magic?
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html><head><ti tle>form</title><script type="text/javascript">
if (document.creat eElement) {
_obj = document.create Element('form') ;
alert('_obj: ' + _obj);
}
function olfunc() {
var f = document.getEle mentById('theFo rm');
var ftags = document.getEle mentsByTagName( 'form');
alert('f = ' + f + '\n' +
'# forms = ' + ftags.length);
}
window.onload = olfunc;
</script></head><body><div ><form id="theForm" action=""><p>
text of a paragraph in theForm</p></form></div></body></html>
The alert boxes say:

_obj: [object HTMLFormElement]

and

f = null
# forms = 0
hj
Jul 23 '05 #1
4 2541
Howard Jess wrote:
[Submitted as a bug to Opera; posted here in hopes of finding an explanation?]

In Opera 8.01 (Linux; Build 1204) and in Opera 7.54 (Windows XP; Build 3865),
my form disappears from the HTML markup (below). To summarize:

1) In a <script> block in the <head> I create a form element (part of
object/feature/bug detection).
2) There's a <form> element defined in the <body>, with the id 'theForm'.
3) The onload function tries to access that form, and also counts the
total number of forms in the document. It fails to get a reference
to the form; the count is 0.

Black magic?
No, less subtle than that. And its not a bug.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html><head><ti tle>form</title><script type="text/javascript">
if (document.creat eElement) {
_obj = document.create Element('form') ;
Here, you create an object but you never append it to anything, so it
never gets created in the DOM of the page.
alert('_obj: ' + _obj);
}
function olfunc() {
var f = document.getEle mentById('theFo rm');
var ftags = document.getEle mentsByTagName( 'form');
alert('f = ' + f + '\n' +
'# forms = ' + ftags.length);
}
window.onload = olfunc;
</script></head><body><div ><form id="theForm" action=""><p>
text of a paragraph in theForm</p></form></div></body></html>
The alert boxes say:

_obj: [object HTMLFormElement]

and

f = null
# forms = 0


forms=0 might be an implementation idea since the form is empty <shrug>

Changing your code to something like this:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>form</title>
<script type="text/javascript">
function olfunc() {
if (document.creat eElement) {
_obj = document.create Element('form') ;
document.body.a ppendChild(_obj );
//above, the obj is appended to the body
//and becomes part of the DOM Tree and can be
//found in the forms collection.
alert('_obj: ' + _obj);
}
var f = document.getEle mentById('theFo rm');
var ftags = document.getEle mentsByTagName( 'form');
alert('f = ' + f + '\n' + '# forms = ' + ftags.length);
}
window.onload = olfunc;
</script>
</head>
<body>
<div>
<form id="theForm" action="">
<p>text of a paragraph in theForm</p>
</form>
</div>
</body>
</html>

Where the call is made after the page has loaded, and it appends the obj
to the body of the page, all give 2 forms elements in IE6, FireFox and
Opera 7 (sorry, too lazy to download/install Opera 8). Perhaps you could
test the above code and see if it still displays the behavior you are
describing?

--
Randy
comp.lang.javas cript FAQ - http://jibbering.com/faq & newsgroup weekly
Jul 23 '05 #2
Randy Webb wrote:
Howard Jess wrote:
[Submitted as a bug to Opera; posted here in hopes of finding an explanation?]

In Opera 8.01 (Linux; Build 1204) and in Opera 7.54 (Windows XP; Build 3865),
my form disappears from the HTML markup (below). To summarize:

1) In a <script> block in the <head> I create a form element (part of
object/feature/bug detection).
2) There's a <form> element defined in the <body>, with the id 'theForm'.
3) The onload function tries to access that form, and also counts the
total number of forms in the document. It fails to get a reference
to the form; the count is 0.

Black magic?


No, less subtle than that. And its not a bug.


Yes, it is; I think you've missed my point ...
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html><head><ti tle>form</title><script type="text/javascript">
if (document.creat eElement) {
_obj = document.create Element('form') ;


Here, you create an object but you never append it to anything, so it
never gets created in the DOM of the page.


That's correct (almost; it's not that I don't append anything to the
form object, but that the form object is not appended/inserted into the
document). But it's irrelevant. I *don't want* this object in the page;
I'm creating it to test the browser for an unrelated problem.

The alert boxes say:

_obj: [object HTMLFormElement]

and

f = null
# forms = 0


forms=0 might be an implementation idea since the form is empty <shrug>


No; there actually is no <form> element in the DOM tree.

Let me restate the bug (yes, I'm pretty sure this should be called a bug):

If you create a <form> element in a script during <head> processing,
then the first <form> element encountered during HTML parsing is lost.
Subsequent <form>s are handled as expected.

The following file illustrates this. It creates a form in the head, and
discards it. The HTML markup contains 2 forms; the onload function only
reports 1. (I've added content to each, so they're not empty.)

If you access this file with the query '?more', then two <div> elements
are also created during <head> processing; each is given a <form> using
its innerHTML (yes, non-standard, but bear with me). The first div
reports childNodes.leng th=0; the second div reports childNodes.leng th=1.
This seems to imply that the existence of a form, even though it's not
part of the document, messes up the parser when it first encounters a
form in markup.

Perhaps the parser it thinks it's already got an open <form>, and so
ignores any more until it sees </form>; but the open <form> is *not* one
that is part of the document, so it disappears ???
Sorry for the length of this, and what follows; I hope someone (from
Opera?) can confirm this?

hj


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html><head><ti tle>form</title><META
HTTP-EQUIV="Content-Type"
CONTENT="text/html; charset=ISO-8859-1"><script type="text/javascript">

if (document.creat eElement) {
var s = '';
obj = document.create Element('form') ;
s += 'obj: ' + obj + '\n';
if (window.locatio n.search.substr ing(1) == 'more') {
div = document.create Element('div');
div.innerHTML = '<form name="form1"></form>';
s += 'div.childNodes : ' + div.childNodes. length +
'\nfirstChild: ' + div.firstChild + '\n';
div2 = document.create Element('div');
div2.innerHTML = '<form name="form2"></form>';
s += 'div2.childNode s: ' + div2.childNodes .length +
'\nfirstChild: ' + div2.firstChild + '\n';
}
alert(s);
}

function olfunc() {
var pre;
var f = document.getEle mentById('theFo rm');
var ftags = document.getEle mentsByTagName( 'form');
alert('f = ' + f + '\n' +
'# forms = ' + ftags.length);
}
window.onload = olfunc;
</script></head><body><div ><form id="theForm" action=""><inpu t type="hidden" name="h1"><p>
text of a paragraph in theForm</p></form><form action="" id="form2"><inp ut
type="hidden" name="h2"></form></div></body></html>
Jul 23 '05 #3
On Tue, 21 Jun 2005 00:50:15 +0200, Howard Jess
<howard..@dhite chnologies.dot. com> wrote:
In Opera 8.01 (Linux; Build 1204) and in Opera 7.54 (Windows XP; Build
3865), my form disappears from the HTML markup (below).


It is a bug, and it's a very annoying one that is hard to work around.
The only suggestion I have is to use a timeout thread for the test - it
can be a very short timeout, still seems to fix it. Is that a workaround
that may work for you?

setTimeout('doc ument.createEle ment("form");/* bug detection here */', 1);
--
Hallvord R. M. Steen
Core QA, Opera Software
http://www.opera.com/
Jul 23 '05 #4

Hallvord R. M. Steen wrote:
On Tue, 21 Jun 2005 00:50:15 +0200, Howard Jess
<howard..@dhite chnologies.dot. com> wrote:
In Opera 8.01 (Linux; Build 1204) and in Opera 7.54 (Windows XP; Build
3865), my form disappears from the HTML markup (below).


It is a bug, and it's a very annoying one that is hard to work around.
The only suggestion I have is to use a timeout thread for the test - it
can be a very short timeout, still seems to fix it. Is that a workaround
that may work for you?

setTimeout('doc ument.createEle ment("form");/* bug detection here */', 1);


Thanks; it just might. I'm a little paranoid, though, that all we can see
is that it *seems* to fix it; without knowing what's really happening,
I'm worried that the bug may pop back up in some other combination of
script and HTML files to be loaded, or who-knows-what-else.

But it's definitely worth my time to do more testing with. Thanks!

hj

Jul 23 '05 #5

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

Similar topics

4
2431
by: Sims | last post by:
Hi, This will validate, (http://validator.w3.org/) <form method="POST" action="" name='xForm' style='background:inherit;'> <table style='background:inherit; width:100%;'> <tr width=80%> <td> <input type="text" value="search" style="width:100%; text-align:left;"> </td>
2
2603
by: Keiron Waites | last post by:
I have the following code: <input type="text" name="search" class="search_top"> <a href="" onclick="window.location='search.inc.php'+document..search. value; return false;" class="search_top">go</a> What do I put within to access the value of the input field search so I can access it's value? Thanks,
3
12936
by: Ben | last post by:
Here's my form: <form name="aForm" method='post'> <input type=file name=file1 onkeypress='KeyPress()'><br> <a id='attachMoreLink' href='javascript:AddFileInput()">Attach More Files </a> <input type=submit value='Done'> </form>
10
8942
by: Phlip | last post by:
HTMListas: (Apologies for I can't Google for this - too many common words.) I have a <form> tag. It thinks I want a <p> break before and after the form. I don't. (My forms are sneaky and inline.) How do I avoid paragraph breaks around a <form> tag?
6
3875
by: snacktime | last post by:
I've searched and searched and have not found a solution to suppress the margin on form or href tags so that there is no space before or after the tag. The only way I have found to do this is to place the tags one after another without any spaces between them. For example, a space gets rendered between these two href's when displayed in firefox or IE. <a href="#"><img border="0" height="10" src="test.gif" width="10" /></a>
4
3728
by: rob c | last post by:
This is a minor thing and only appears in IE (so far), but I'd like to know to correct it (if possible). Whenever I use a form on a webpage, Explorer always leaves a blank line following the </form> tag but Mozilla doesn't. Is there a way to supress the blank line? Thanks Rob www.rcp.ca
19
2154
by: Coward 9 | last post by:
HI, I saw in an example hello.aspx, there is a <form tagbeing used like <form runat="server> I search all html tag references and could NOT find "runat" attributes for <formtag. which reference should I use in order to find that?
10
14172
by: neverquit | last post by:
hi , Iam Nagesh,Begineer in using Ajax,well i have been using ajax in application, i have faced a problem while placing the responseTEXT into the <div> tag positioned inside the <form> tag iam able to get the response in the <div> tag in mozilla (im takingthe HTML response), <script> function confirm() { xmlHttp=GetXmlHttpObject(); if (xmlHttp==null)
0
9456
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9275
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9872
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9843
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9713
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7248
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5304
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3805
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 we have to send another system
3
2666
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.