473,387 Members | 1,561 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

element.children has no properties (mozilla only)

I'm not sure if this is the correct forum for platform specific
(Mozilla/Firefox) javascript problems, so just shout and point me to the
correct newsgroup if I'm being bad.

Here's the deal...

html file (generated using .NET 2.0 beta2):

<form method="post" action="Test2.aspx" id="form1">

<div>
<input type="hidden" ... />
<input type="hidden" ... />
<input type="hidden" ... />
<input type="hidden" ... />
<input type="hidden" ... />
<input type="hidden" ... />
</div>

<script type="text/javascript">
<!--
var theForm = document.forms['form1'];
if (!theForm) {
theForm = document.form1;
}
function __doPostBack(eventTarget, eventArgument) {
if (!theForm.onsubmit || (theForm.onsubmit() != false)) {
theForm.__EVENTTARGET.value = eventTarget;
theForm.__EVENTARGUMENT.value = eventArgument;
theForm.submit();
}
}
// -->
</script>

<select name="ddl" id="ddl">
<option value="hi">hi</option>
<option value="there">there</option>
</select>

...BLAH BLAH BLAH

...a bunch of anchors with "javascript:" hrefs.

<script type="text/javascript">
<!--
var pageUrl='/Test2.aspx'; // localhost
WebForm_InitCallback(); // <-------- Error in here
...more js
-->
</script>
</form>

Javascript causing error:

function WebForm_InitCallback() {
var count = theForm.elements.length;
var element;
for (var i = 0; i < count; i++) {
element = theForm.elements[i];
var tagName = element.tagName.toLowerCase();
if (tagName == "input") {
var type = element.type;
if (type == "text" || type == "hidden" || type ==
"password" ||
((type == "checkbox" || type == "radio") &&
element.checked)) {
__theFormPostData += element.name + "=" +
WebForm_EncodeCallback(element.value) + "&";
}
}
else if (tagName == "select") {

// ***ERROR***
var selectCount = element.children.length; // <--
// ***ERROR***

for (var j = 0; j < selectCount; j++) {
var selectChild = element.children[j];
if ((selectChild.tagName.toLowerCase() == "option")
&& (selectChild.selected == true)) {
__theFormPostData += element.name + "=" +
WebForm_EncodeCallback(selectChild.value) + "&";
}
}
}
else if (tagName == "textarea") {
__theFormPostData += element.name + "=" +
WebForm_EncodeCallback(element.value) + "&";
}
}
}

This clears IE fine, but FireFox 1.0.4 tosses the error

Error: element.children has no properties
Source File: ...

Does anyone know if there is something special about FireFox's "select"
element.children property that would cause this?

As a background, this code is autogenerated by ASP.NET in conjunction
with the TreeView control when it is set to use out-of-band callbacks to
populate TreeNodes... I can provide a live demo if you contact me directly.

Thanks in advance,
Luke Dalessandro
Jul 23 '05 #1
6 13318


Luke Dalessandro wrote:

else if (tagName == "select") {

// ***ERROR***
var selectCount = element.children.length; // <--
// ***ERROR***


children is part of the IE DOM since IE 4 but it is not part of the W3C
DOM that Mozilla implements. The closest in that object model is
childNodes which contains all child nodes (including text nodes) while
children contains all child elements.

As for that code I would simply loop through element.options once it has
been established that element is a select element.

--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 23 '05 #2
Martin,

Thanks for the pointer... unfortunately, I have no control over the
code. The script is autogenerated through a call to a predetermined
handler in .NET (ie, the framework automatically add a

<script
src="/WebResource.axd?d=MSFJ4SIWhD3cinjlZxIy4w2&amp;t=63 2546115913125000"
type="text/javascript"></script>

tag when rendering the page.

Looks like MS is continuing to write broken code. sigh...

Luke

Martin Honnen wrote:


Luke Dalessandro wrote:

else if (tagName == "select") {

// ***ERROR***
var selectCount = element.children.length; // <--
// ***ERROR***

children is part of the IE DOM since IE 4 but it is not part of the W3C
DOM that Mozilla implements. The closest in that object model is
childNodes which contains all child nodes (including text nodes) while
children contains all child elements.

As for that code I would simply loop through element.options once it has
been established that element is a select element.

Jul 23 '05 #3
Hi Luke,

I use this piece of code to correct the problem:
<code>
if (typeof Node != 'undefined') {
if (typeof Node.children == 'undefined') {
eval('Node.prototype.children getter = function() {return
this.childNodes;}');
}
}
</code>
And wait until MS fixes the problem.

Diego

"Luke Dalessandro" <us****@luked.net> schreef in bericht
news:V5****************@news01.roc.ny...
I'm not sure if this is the correct forum for platform specific
(Mozilla/Firefox) javascript problems, so just shout and point me to the
correct newsgroup if I'm being bad.

Here's the deal...

html file (generated using .NET 2.0 beta2):

<form method="post" action="Test2.aspx" id="form1">

<div>
<input type="hidden" ... />
<input type="hidden" ... />
<input type="hidden" ... />
<input type="hidden" ... />
<input type="hidden" ... />
<input type="hidden" ... />
</div>

<script type="text/javascript">
<!--
var theForm = document.forms['form1'];
if (!theForm) {
theForm = document.form1;
}
function __doPostBack(eventTarget, eventArgument) {
if (!theForm.onsubmit || (theForm.onsubmit() != false)) {
theForm.__EVENTTARGET.value = eventTarget;
theForm.__EVENTARGUMENT.value = eventArgument;
theForm.submit();
}
}
// -->
</script>

<select name="ddl" id="ddl">
<option value="hi">hi</option>
<option value="there">there</option>
</select>

...BLAH BLAH BLAH

...a bunch of anchors with "javascript:" hrefs.

<script type="text/javascript">
<!--
var pageUrl='/Test2.aspx'; // localhost
WebForm_InitCallback(); // <-------- Error in here
...more js
-->
</script>
</form>

Javascript causing error:

function WebForm_InitCallback() {
var count = theForm.elements.length;
var element;
for (var i = 0; i < count; i++) {
element = theForm.elements[i];
var tagName = element.tagName.toLowerCase();
if (tagName == "input") {
var type = element.type;
if (type == "text" || type == "hidden" || type ==
"password" ||
((type == "checkbox" || type == "radio") &&
element.checked)) {
__theFormPostData += element.name + "=" +
WebForm_EncodeCallback(element.value) + "&";
}
}
else if (tagName == "select") {

// ***ERROR***
var selectCount = element.children.length; // <--
// ***ERROR***

for (var j = 0; j < selectCount; j++) {
var selectChild = element.children[j];
if ((selectChild.tagName.toLowerCase() == "option")
&& (selectChild.selected == true)) {
__theFormPostData += element.name + "=" +
WebForm_EncodeCallback(selectChild.value) + "&";
}
}
}
else if (tagName == "textarea") {
__theFormPostData += element.name + "=" +
WebForm_EncodeCallback(element.value) + "&";
}
}
}

This clears IE fine, but FireFox 1.0.4 tosses the error

Error: element.children has no properties
Source File: ...

Does anyone know if there is something special about FireFox's "select"
element.children property that would cause this?

As a background, this code is autogenerated by ASP.NET in conjunction
with the TreeView control when it is set to use out-of-band callbacks to
populate TreeNodes... I can provide a live demo if you contact me directly.
Thanks in advance,
Luke Dalessandro

Jul 23 '05 #4
I had the same problem myself. You can work around the problem by
adding a call to a function like the one I've written below. I
basically just added a check to see if the children property exist.

If you have a <asp:button> on your page just do this in the codebehind:

mybutton.Attributes.Add( "onclick", "PrepareForPostBack();" );

This should ensure it would run the Prepare function before doing the
actual postback.

Regards,
Mikael Svenson
C# Developer
-JAVASCRIPT--

function PrepareForPostBack()
{
try { WebForm_InitCallback();}
catch( e )
{
WebForm_InitCallback_Mozilla();
}
}

function WebForm_InitCallback_Mozilla() {
var count = theForm.elements.length;
var element;
for (var i = 0; i < count; i++) {
element = theForm.elements[i];
var tagName = element.tagName.toLowerCase();
if (tagName == "input") {
var type = element.type;
if (type == "text" || type == "hidden" || type ==
"password" ||
((type == "checkbox" || type == "radio") &&
element.checked)) {
__theFormPostData += element.name + "=" +
WebForm_EncodeCallback(element.value) + "&";
}
}
else if (tagName == "select") {
var children;
if( typeof element.children == 'undefined' ) {
<!-- We are using mozilla -->
children = element.childNodes;
}
else
{
<!-- we are using IE -->
children = element.children;
}

var selectCount = children.length;
for (var j = 0; j < selectCount; j++) {
var selectChild = children[j];
if ((selectChild.tagName.toLowerCase() == "option") &&
(selectChild.selected == true)) {
__theFormPostData += element.name + "=" +
WebForm_EncodeCallback(selectChild.value) + "&";
}
}
}
else if (tagName == "textarea") {
__theFormPostData += element.name + "=" +
WebForm_EncodeCallback(element.value) + "&";
}
}
}

Diego wrote:
Hi Luke,

I use this piece of code to correct the problem:
<code>
if (typeof Node != 'undefined') {
if (typeof Node.children == 'undefined') {
eval('Node.prototype.children getter = function() {return
this.childNodes;}');
}
}
</code>
And wait until MS fixes the problem.

Diego

"Luke Dalessandro" <us****@luked.net> schreef in bericht
news:V5****************@news01.roc.ny...
I'm not sure if this is the correct forum for platform specific
(Mozilla/Firefox) javascript problems, so just shout and point me to the
correct newsgroup if I'm being bad.

Here's the deal...

html file (generated using .NET 2.0 beta2):

<form method="post" action="Test2.aspx" id="form1">

<div>
<input type="hidden" ... />
<input type="hidden" ... />
<input type="hidden" ... />
<input type="hidden" ... />
<input type="hidden" ... />
<input type="hidden" ... />
</div>

<script type="text/javascript">
<!--
var theForm = document.forms['form1'];
if (!theForm) {
theForm = document.form1;
}
function __doPostBack(eventTarget, eventArgument) {
if (!theForm.onsubmit || (theForm.onsubmit() != false)) {
theForm.__EVENTTARGET.value = eventTarget;
theForm.__EVENTARGUMENT.value = eventArgument;
theForm.submit();
}
}
// -->
</script>

<select name="ddl" id="ddl">
<option value="hi">hi</option>
<option value="there">there</option>
</select>

...BLAH BLAH BLAH

...a bunch of anchors with "javascript:" hrefs.

<script type="text/javascript">
<!--
var pageUrl='/Test2.aspx'; // localhost
WebForm_InitCallback(); // <-------- Error in here
...more js
-->
</script>
</form>

Javascript causing error:

function WebForm_InitCallback() {
var count = theForm.elements.length;
var element;
for (var i = 0; i < count; i++) {
element = theForm.elements[i];
var tagName = element.tagName.toLowerCase();
if (tagName == "input") {
var type = element.type;
if (type == "text" || type == "hidden" || type ==
"password" ||
((type == "checkbox" || type == "radio") &&
element.checked)) {
__theFormPostData += element.name + "=" +
WebForm_EncodeCallback(element.value) + "&";
}
}
else if (tagName == "select") {

// ***ERROR***
var selectCount = element.children.length; // <--
// ***ERROR***

for (var j = 0; j < selectCount; j++) {
var selectChild = element.children[j];
if ((selectChild.tagName.toLowerCase() == "option")
&& (selectChild.selected == true)) {
__theFormPostData += element.name + "=" +
WebForm_EncodeCallback(selectChild.value) + "&";
}
}
}
else if (tagName == "textarea") {
__theFormPostData += element.name + "=" +
WebForm_EncodeCallback(element.value) + "&";
}
}
}

This clears IE fine, but FireFox 1.0.4 tosses the error

Error: element.children has no properties
Source File: ...

Does anyone know if there is something special about FireFox's "select"
element.children property that would cause this?

As a background, this code is autogenerated by ASP.NET in conjunction
with the TreeView control when it is set to use out-of-band callbacks to
populate TreeNodes... I can provide a live demo if you contact me

directly.

Thanks in advance,
Luke Dalessandro


Jul 23 '05 #5
Forgot to mention that you have to do

_theFormPostData = '';

before running WebForm_InitCallback, or put it as the first line. If
not you will get double values.

Regards,
Mikael Svenson
C# developer
Jul 23 '05 #6
ASM
Luke Dalessandro wrote:
I'm not sure if this is the correct forum for platform specific
(Mozilla/Firefox) javascript problems, so just shout and point me to the
correct newsgroup if I'm being bad.

Here's the deal...

html file (generated using .NET 2.0 beta2):

<form method="post" action="Test2.aspx" id="form1">

<div>
<input type="hidden" ... />
<input type="hidden" ... />
<input type="hidden" ... />
<input type="hidden" ... />
<input type="hidden" ... />
<input type="hidden" ... />
</div>

<script type="text/javascript">
<!--
var theForm = document.forms['form1'];
if (!theForm) {
theForm = document.form1;
}
function __doPostBack(eventTarget, eventArgument) {
if (!theForm.onsubmit || (theForm.onsubmit() != false)) {
theForm.__EVENTTARGET.value = eventTarget;
theForm.target = enventTarget
theForm.__EVENTARGUMENT.value = eventArgument;
theForm.submit();
}
}
// -->
</script>

<select name="ddl" id="ddl">
<option value="hi">hi</option>
<option value="there">there</option>
</select>

...BLAH BLAH BLAH

...a bunch of anchors with "javascript:" hrefs.

<script type="text/javascript">
<!--
var pageUrl='/Test2.aspx'; // localhost
WebForm_InitCallback(); // <-------- Error in here
...more js
-->
</script>
</form>

Javascript causing error:

function WebForm_InitCallback() {
and with some less lines and calabistic words ?

var __theFormPostData = ''; // if absolutly needed

function WebForm_InitCallback() {
// would prefer to set theForm here
// theForm = document.forms[0];
var F = theForm; // hope theForm was ok ! ?
var D = '';
for(var i=0;i<F.length;i++) {
if(F[i].tagName.toLowerCase()=='select') {
if(F[i].selectedIndex!=0)
D += F[i].name+'='+F[i].options[F[i].selectedIndex].value+'&';
}
if(F[i].tagName.toLowerCase()=='textarea')
if(F[i].value!='')
D += F[i].name+'='+escape(F[i].value)+'&';
var e = F[i].type.toLowerCase();
if((e=='text'||e=='password')&&e.value!=''||
(e=='checkbox'||e=='radio')&&F[i].checked)
D += F[i].name+'='+escape(F[i].value)+'&';
}
if(D=='') alert('Form empty');
else D = D.substring(0,D.length-1)
__theFormPostData = D;
}
As a background, this code is autogenerated by ASP.NET in conjunction
with the TreeView control when it is set to use out-of-band callbacks to
populate TreeNodes... I can provide a live demo if you contact me directly.


if it works like that : No, thank you very very much
--
Stephane Moriaux et son [moins] vieux Mac
Jul 23 '05 #7

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

Similar topics

3
by: Greg Brunet | last post by:
In puzzling over classes, I'm wondering if classes can have read-only static properties? I certainly seem to be able to do create static properties like this: class C(object): count = 0 def...
9
by: Paul Moore | last post by:
I have a class with a read-only attribute, and I want to add a unit test to ensure that it really *is* read-only. I can do this as def test_readonly(self): """Value and multiplier must be...
1
by: cwj | last post by:
I have a form where you first select a state. The next step is to choose a county. Since I don't know what counties to show until the state is selected I am building the county menu with...
13
by: Julia Peterwitz | last post by:
I have a function that works with explorer but not with netscape. The problem is the function at line 5. 1 fSetSelectedDay(myElement){ 2 /* 3 ... 4 */ 5 var elementText =...
8
by: Nicolás Lichtmaier | last post by:
Hi, some time ago I've written an article about this issue. It explain some differences in Explorer's and Mozilla's JavaScript/DOM. It has recently changed its URL, This is the new one: ...
5
by: Dan Novak | last post by:
Hello, I'm trying to apply different backgrounds to a page based on the BODY element class. It's working on some browsers but not on others. I've searched Google and the groups, pored through...
8
by: Doug Lerner | last post by:
I have this snippet of client side code running: var makeField = document.forms; alert("makeFieldName name,length,type=" + makeFieldName + ", " + makeField.name + "," + makeField.length + ","...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...

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.