By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,598 Members | 1,897 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,598 IT Pros & Developers. It's quick & easy.

IE + javascript = bug?

P: n/a
Hello everyone,

I am running some code in IE 6.0. It seems as though there is a bug
with .js functionality in IE though.

I have the following in an HTML form:

<FORM name="FrmXTest" id="FormTest" method="post">
</FORM>

<FORM name="FrmX1" id="Form2" method="post">
</FORM>

<FORM name="FrmX" id="Form3" method="post" >
....
[many more controls/objects]
....
</FORM>
I would think that the following javascript commands:

alert("forms 0 ->" + document.forms[0]);
Would produce: [object]

alert("forms 0 NAME ->" + document.forms[0].name);
Would produce: FrmXTest

alert("forms 1 ->" + document.forms[1]);
Would produce: [object]

alert("forms 1 NAME ->" + document.forms[1].name);
Would produce: FrmX1

***But*** what I actually get is:
alert("forms 0 ->" + document.forms[0]);
Produces: [object]

alert("forms 0 NAME ->" + document.forms[0].name);
Produces: <blank>

alert("forms 1 ->" + document.forms[1]);
Produces: [object]

alert("forms 1 NAME ->" + document.forms[1].name);
Produces: FrmX1

The name of the form in the 0 spot of the array is "blank" while the
name of the form in the 1 spot of the array is "FrmX1"??? Are things
supposed to work like this or is it some kind of bug?

TIA

Oct 1 '05 #1
Share this Question
Share on Google+
7 Replies


P: n/a
milkyway wrote:
Hello everyone,

I am running some code in IE 6.0. It seems as though there is a bug
with .js functionality in IE though.
[...]
The name of the form in the 0 spot of the array is "blank" while the
name of the form in the 1 spot of the array is "FrmX1"??? Are things
supposed to work like this or is it some kind of bug?


I can't replicate the error, try this test:

<html> <title>Form play</title>
<body>
<FORM name="FrmXTest" id="FormTest" method="post">
<input>
</FORM>
<FORM name="FrmX1" id="Form2" method="post">
<input>
</FORM>
<FORM name="FrmX" id="Form3" method="post" >
<input>
</FORM>

<script type="text/javascript">
var allForms = document.forms;
var str=[];
for (var i=0, j=allForms.length; i<j; i++){
str[i] = 'Form ' + i + ' id: ' + allForms[i].id
+ ' name: ' + ' ' + allForms[i].name;
}
document.write(str.join('<br>'));
</script>

</body>
</html>


--
Rob
Oct 2 '05 #2

P: n/a
Hello and thank you for responding ;-)

When I run the code snippet, I get the following results:

Form 0 id: aspnetForm name:
Form 1 id: Form2 name: FrmX1
Form 2 id: Form3 name: FrmX

Oct 2 '05 #3

P: n/a
"milkyway" <d0******@hotmail.com> wrote in message
news:11*********************@g49g2000cwa.googlegro ups.com...
Hello and thank you for responding ;-)

When I run the code snippet, I get the following results:

Form 0 id: aspnetForm name:
Form 1 id: Form2 name: FrmX1
Form 2 id: Form3 name: FrmX

You must be doing something else, not just running the code by RobG, as there is
no aspNetForm.
Are you sure there isn't some code you're hiding?
I tried this based on your original sample and everything works fine.

<html>
<head>
<title>Form Names</title>
<script type="text/javascript">
function showFormInfo()
{
var colForms = document.forms;
var sMessage = "";
for (var i = 0; i < colForms.length; i++)
{
sMessage += "ID: " + colForms[i].id + "\tName: " + colForms[i].name +
"\n";
}
showOutput(sMessage);
}

function showOutput(Text)
{
document.getElementById("txtOutput").value = Text;
}
</script>
</head>
<body>
<FORM name="FrmXTest" id="FormTest" method="post"></FORM>
<FORM name="FrmX1" id="Form2" method="post"></FORM>
<FORM name="FrmX" id="Form3" method="post"></FORM>
<input type="button" value="Show Forms Info" onclick="showFormInfo();"><br>
<textarea id="txtOutput" cols="40" rows="10"></textarea>
</body>
</html>

--

Joe
Oct 2 '05 #4

P: n/a
I am using the master below that references the .aspx page holding the
3 form definitions. I ran it again just a second ago (using the code
RobG sent) and got the same results.

The line below:
<asp:contentplaceholder id="PageContent" runat="server" />
brings in the page I am using.

At the top of that page is:

<%@ Page Language="C#"
MasterPageFile="~/FrontEnds/UserInterface/Application.master"
CodeFile="Test.aspx.cs" Inherits="Test" Title="Login" %>
<asp:content contentplaceholderid="PageContent" runat="Server">

Would this cause a problem?

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
<title>Untitled Page</title>
<LINK rel="stylesheet" type="text/css" href="~/styles.css">
<META http-equiv=Content-Type content="text/html;
charset=windows-1252">
<script type="text/javascript"
src="data_check_functions.js"></script>
<script type="text/javascript" src="row_functions.js"></script>
</head>
<body onload="load_data();" >
<form id="form1" runat="server">
<table border="1" cellpadding="5" cellspacing="0" width="100%"
height="100%">
<tr>
<!-- site navigation and site essentials: contact info,
etc. -->
<td colspan="2" align="left" class="nav" style="width:
167px" >
<asp:hyperlink
navigateurl="~/FrontEnds/UserInterface/Test.aspx" runat="server"
id="Hyperlink6">Depend</asp:hyperlink>
</td>
</tr>
<tr>
<td colspan="2" align="left" class="body">
<!-- this is the placeholder for the page content -->
<asp:contentplaceholder id="PageContent" runat="server"
/>

<br />
</td>
</tr>
</table>
</form>
</body>
</html>

Oct 2 '05 #5

P: n/a
milkyway wrote:
I am using the master below that references the .aspx page holding the
3 form definitions. I ran it again just a second ago (using the code
RobG sent) and got the same results.


Please don't post the source at your server but the source that is shown
at the client's machine. The error probably is within your asp pages not
in IE. It seems as if the first form element will be replaced by another
form with another id and no name.

FuP set to microsoft.public.scripting.jscript
Daniel
Oct 4 '05 #6

P: n/a
"milkyway" <d0******@hotmail.com> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.com...
I am using the master below that references the .aspx page holding the
3 form definitions. I ran it again just a second ago (using the code
RobG sent) and got the same results.

The line below:
<asp:contentplaceholder id="PageContent" runat="server" />
brings in the page I am using.

At the top of that page is:

<%@ Page Language="C#"
MasterPageFile="~/FrontEnds/UserInterface/Application.master"
CodeFile="Test.aspx.cs" Inherits="Test" Title="Login" %>
<asp:content contentplaceholderid="PageContent" runat="Server">

Would this cause a problem?

This is the first time you have mentioned using aspx, didn't you think it might
be relevant?
Aspx version 1.0 doen't support multiple visible forms in a page, it
automatically creates a form itself so your forms will be nested within that
leading to the strange behaviour.
If you need multiple forms either use version 2.0 or see
http://msdn.microsoft.com/msdnmag/is...9/CuttingEdge/, there is an article
about this subject.
--

Joe

Oct 4 '05 #7

P: n/a
I am new to this area (I normally do .jsp/unix) and had not idea that
aspx was the route of the problem.

But thanks for the information.

Oct 5 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.