473,399 Members | 3,888 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,399 software developers and data experts.

Why, please, this strange behavior?

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.

--
Fabri
(Incredibile come si tenda a credere di piu` a Rossi. (cit.))
Jul 23 '05 #1
3 1089
Fabri wrote:
<snip>
I think because the page, in the second case, is not completely loaded.


I think that's right. How about using the onload event?

<script type='text/javascript'>
function doit(){
alert('1st alert');
var ddiv1 = document.getElementById('1');
ddiv1.innerHTML = '1 elaborato con successo...<br>';
alert('2nd alert');
}
</script>
</head>

<body onload="doit()";>
<div id='1'>
</div>
Jul 23 '05 #2
On Thu, 18 Nov 2004 09:07:35 +0100, Fabri <no@sp.am> wrote:

[snip]
and this one NO?

--------------------------------------------------------------
<div id='1'></div>
<script language='javascript'><!--
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

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.
Jul 23 '05 #3
Michael Winter wrote:
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.
--
Fabri
(Incredibile come si tenda a credere di piu` a Rossi. (cit.))
Jul 23 '05 #4

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

Similar topics

87
by: expertware | last post by:
Dear friends, My name is Pamela, I know little about CSS, but I would like to ask a question I have an image on a web page within a css layer: <DIV ID=MyLayer STYLE = "position:...
5
by: cpptutor2000 | last post by:
I am compiling and running the following code snippet on a Linux box - I am really puzzled by the answers. Could someone please tell me what might be wrong? void test(){ int m = 0; int n = 0;...
31
by: DeltaOne | last post by:
#include<stdio.h> typedef struct test{ int i; int j; }test; main(){ test var; var.i=10; var.j=20;
1
by: Alexander Inochkin | last post by:
Hi! I found same strange behavior of ASP.NET. It is possible this is the bug. Follow the steps:
2
by: Webdiyer | last post by:
Hi, We all know that the return value of Math.Log(8,2) is 3,but how about (int)Math.Log(8,2)? On my machine,the return value of (int)Math.Log(8,2) is strange enough! it's not 3 but 2 ! I've...
0
by: ivb | last post by:
Hi all, I am using DB2 8.1.11.1 on NT with ASP.NET 1.1 When application make connection to database (via ADO.NET), it set "Connection timeout" parameter to 30 seconds. After, when my webpage...
6
by: Joseph Geretz | last post by:
Writing an Outlook AddIn with C#. For the user interface within Outlook I'm adding matching pairs of Toolbar buttons and Menu items. All of the buttons and menu items are wired up to send events to...
1
by: Nicholas Palmer | last post by:
Hi all, Got a question about the AspCompat=true page property. First a little background. We have an ASP.NET app that uses two COM components. The first is the Microsoft OWC 11 components and...
31
by: Simply_Red | last post by:
i'm sorry i posted this in other groupes, and i didn't see it, and as this group is most actif, i repost it here, and sorry for mutliposting: Hi, i'm using VC6, i have this declaration: ...
19
by: david | last post by:
I took old code and decided to modify it a bit, and I just noticed that it does not compile at all and before server one of severs (main) crashed in the system it was working fine (I am really sure...
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: 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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.