Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Vbscript fails to update the screen

Status
Not open for further replies.

martynj

Programmer
Oct 19, 2001
11
0
0
GB
Why is it that Vbscript seems to not update the screen.
If I have a div which i decide to make visible and then hide within a script it seems to not do anything unless I put in a msgbox in the script. This then seems to force the script to use the output stream. In Vb i suppose we would use doevents to make sure that the operating system can paint the screen.

Has anyone got any ideas on this. What do others do..use settimeout ?

Regards

Martyn
 
What do you mean by "output stream?"

Here is a working example showing hiding/showing and replacing the contents of a <DIV>:
Code:
<HTML>
<HEAD>
<SCRIPT language=vbscript>
Sub window_onload()
  div1.innerText = &quot;Replacement text&quot;
End Sub
Sub btn1_onclick()
  div1.style.visibility = &quot;visible&quot;
End Sub
Sub btn2_onclick()
  div1.innerText = &quot;Even more text&quot;
End Sub
</SCRIPT>
</HEAD>
<BODY>
  <INPUT type=button id=btn1 value=1st>
  <INPUT type=button id=btn2 value=2nd>
  <DIV id=div1 style=&quot;visibility: hidden&quot;>
    Original text
  </DIV>
</BODY>
</HTML>
Are you trying to use document.write or .writeln? These are not intended for general-purpose DHTML. They are only to be used in pre-pageload script, or if you want to build a fresh page. In the latter case you use document.open and document.close as well.

You may find lots of examples where this rule is broken, but the behavior may be unpredictable.

See:

 
if you can't use document.write or .writeln for general dhtml, what CAN one use in vbscript?
 
I posted this some time ago and since have found out why via MSDN. When a script is running it has control of what they class as the output pump. It is possible, and i have situations where changes to the screen do not happen when instructed through script.

You have to use settimeout to temporarily give control back to the browser so that it can update the screen, a bit like doevents in vb. It works.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top