G
Guest
Okay, after much research, I have discovered a few interesting things in
ASP.NET.
I have a MasterPage that has a WebForm on it and it looks like this:
<body>
<form id="controls" runat="server">
<div id="bodyColumn">
<asp:ContentPlaceHolder id="bodyContentPlaceHolder" runat="server">
</asp:ContentPlaceHolder>
</div>
</form>
</body>
In a page the dervies from the MasterPage, I use another form but a standard
HTML Form that does not have the "runat=server" attribute.
<form name="MyForm">
<input type="text" name="zipcode" />
</form>
In JavaScript, I cannot do any of the following with success:
document.MyForm.zipcode.value;
document.forms["MyForm"].zipcode.value;
But these work:
document.forms[0].item("zipcode", 0).value;
document.forms[0].zipcode.value;
My question is really why do these behave in that way?
I did some further investigation and found that this snippet:
document.forms[0].name;
....returns a string: "aspnetForm"
However, if I add another standard form to my child page:
<form name="MyForm2">
<input type="text" name="phone">
</form>
then, doing this:
document.MyForm2.phone.value;
document.forms["MyForm2"].phone.value;
....does work. And, this:
document.forms[1].name;
....returns "MyForm2".
Why is all this happening?
Gurus on deck!
Thanks in advance,
Amrit
ASP.NET.
I have a MasterPage that has a WebForm on it and it looks like this:
<body>
<form id="controls" runat="server">
<div id="bodyColumn">
<asp:ContentPlaceHolder id="bodyContentPlaceHolder" runat="server">
</asp:ContentPlaceHolder>
</div>
</form>
</body>
In a page the dervies from the MasterPage, I use another form but a standard
HTML Form that does not have the "runat=server" attribute.
<form name="MyForm">
<input type="text" name="zipcode" />
</form>
In JavaScript, I cannot do any of the following with success:
document.MyForm.zipcode.value;
document.forms["MyForm"].zipcode.value;
But these work:
document.forms[0].item("zipcode", 0).value;
document.forms[0].zipcode.value;
My question is really why do these behave in that way?
I did some further investigation and found that this snippet:
document.forms[0].name;
....returns a string: "aspnetForm"
However, if I add another standard form to my child page:
<form name="MyForm2">
<input type="text" name="phone">
</form>
then, doing this:
document.MyForm2.phone.value;
document.forms["MyForm2"].phone.value;
....does work. And, this:
document.forms[1].name;
....returns "MyForm2".
Why is all this happening?
Gurus on deck!
Thanks in advance,
Amrit