Why, please, this strange behavior?

F

Fabri

Why this script:



--------------------------------------------------------------
<div id='1'></div>
<script language='javascript'><!--

function pippo(){
alert('primo alert');
var ddiv1 = document.getElementById('1');
ddiv1.innerHTML = '1 elaborato con successo...<br>';
alert('secondo alert');
}
//--></script>
<a href="#" onClick="pippo();">Vai</a>
--------------------------------------------------------------







and this one NO?


--------------------------------------------------------------
<div id='1'></div>
<script language='javascript'><!--
alert('primo alert');
var ddiv1 = document.getElementById('1');
ddiv1.innerHTML = '1 elaborato con successo...<br>';
alert('secondo alert');
//--></script>
--------------------------------------------------------------

Tested on IE and FF, only first alert works in second case.

I think because the page, in the second case, is not completely loaded.

Isn't it?

And if it is how can I do?

Any help appreciated.

Regards.
 
M

Michael Winter

[snip]
and this one NO?

Minor points:

1) The language attribute has been deprecated for over six years. Use the
(required) type attribute instead.

<script type="text/javascript">

2) The practice of hiding scripts using SGML comments is also out-of-date.
You can remove them.
alert('primo alert');
var ddiv1 = document.getElementById('1');
ddiv1.innerHTML = '1 elaborato con successo...<br>';
alert('secondo alert');
//--></script>
--------------------------------------------------------------

Tested on IE and FF, only first alert works in second case.

I think because the page, in the second case, is not completely loaded.

Isn't it?

I would actually say, no. In my experience, as long as the element in
question - a DIV here - has been parsed, you should be able to access it
via a script.

What could happen in your case is that because the DIV has no content, the
browser is ignoring it. Try putting something - text, for example - in it
and try again.

If you're still having trouble, could you post a full example. I can't
replicate the problem, so it might be something specific that you're doing.

Mike
 
F

Fabri

Michael said:
What could happen in your case is that because the DIV has no content,
the browser is ignoring it. Try putting something - text, for example -
in it and try again.

Good Job Michael :)


I post to you (and to the group) what did:

I assume that you know some vbscript.

<%

for idx = 1 to 5
response.Write("<div id='" & idx & "' style='display: none;'>a</div>")
next


arrTest = array("a", "b", "c", "d", "e")

cnt = 1

response.Flush()

for idx = lbound(arrTest) to ubound(arrTest)

response.Flush()
response.Write(vbcrlf)
response.Write("<script language='javascript'><!--")
response.Write(vbcrlf)
response.Write(vbcrlf)
response.Write(" var ddiv" & cnt & " = document.getElementById('" &
cnt & "');")
response.Write(vbcrlf)
response.Write(" ddiv" & cnt & ".innerHTML = '" & cnt & "
succesfully elaborated...<br>';")
response.Write(vbcrlf)
response.Write(" ddiv" & cnt & ".style.display = '';")
response.Write(vbcrlf)
response.Write(vbcrlf)
response.Write("//--></script>")
response.Flush()


' Here I try to give some delay to sequentially let the DIVs to be drawed

for ix = 1 to 100000
response.Flush()
next

cnt = cnt + 1

response.Flush()

next
%>



It works.

Regards.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top