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

element.children has no properties (mozilla only)

P: n/a
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
Share this Question
Share on Google+
6 Replies


P: n/a


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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.