473,387 Members | 1,650 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.

Reload page?

joe
I have a Javascript page which needs to be dynamically changed depending on user
input. The whole page is written on document.write() output.

I am still new to Javascript and run into problems with page reload. When user
presses a button on my page most functions should clear the page and repaint it
using my wholepage() function. After a couple of repaint the page goes into some
error. Am I supposed to clear the div's in the page or wot?

The pseudo code is here:

<html> <head>
....
<SCRIPT LANGUAGE="JavaScript">
....
[lots of code & functions including wholepage()]
....
function wholepage() {
document.write("<body bgcolor=\"#CCCCCC\">");
document.write("<div id=\"Layer1\" style=\"position:absolute;");
....[lots of code]
document.write("</div> </body>");
return true;}
....

function updateit() {
wholepage();
return true;}

</SCRIPT>
</HEAD>

<SCRIPT LANGUAGE="JavaScript">
wholepage()
</SCRIPT>

</html>
May 8 '06 #1
12 3084
ASM
joe a écrit :
I have a Javascript page which needs to be dynamically changed depending on user
input. The whole page is written on document.write() output.

I am still new to Javascript and run into problems with page reload. When user
presses a button on my page most functions should clear the page and repaint it
using my wholepage() function. After a couple of repaint the page goes into some
error. Am I supposed to clear the div's in the page or wot?

The pseudo code is here:

<html> <head>
...
<SCRIPT LANGUAGE="JavaScript">
...
[lots of code & functions including wholepage()]
...
function wholepage() {


prefer something like :

var txt = '';
txt += '<body bgcolor="#CCCCCC">';
txt += '<div id="Layer1" style="position:absolute;';

and so on

txt += '<\/div><\/body><\/html>';

then

with(document){open();write(txt);close();}
}
--
Stephane Moriaux et son [moins] vieux Mac
May 8 '06 #2
joe
ASM <st*********************@wanadoo.fr.invalid> wrote:
joe a écrit :
I have a Javascript page which needs to be dynamically changed depending on user
input. The whole page is written on document.write() output.

I am still new to Javascript and run into problems with page reload. When user
presses a button on my page most functions should clear the page and repaint it
using my wholepage() function. After a couple of repaint the page goes into some
error. Am I supposed to clear the div's in the page or wot?

The pseudo code is here:

<html> <head>
...
<SCRIPT LANGUAGE="JavaScript">
...
[lots of code & functions including wholepage()]
...
function wholepage() {


prefer something like :

var txt = '';
txt += '<body bgcolor="#CCCCCC">';
txt += '<div id="Layer1" style="position:absolute;';

and so on

txt += '<\/div><\/body><\/html>';

then

with(document){open();write(txt);close();}
}


That what I'm doing but with document.write().
What does the close() do?
May 8 '06 #3
joe wrote:
I have a Javascript page which needs to be dynamically changed depending on user
input. The whole page is written on document.write() output.
That does not seem like a good idea. You should just modify the bits
that need to change, not re-write the entire page.

I am still new to Javascript and run into problems with page reload. When user
presses a button on my page most functions should clear the page and repaint it
using my wholepage() function. After a couple of repaint the page goes into some
error. Am I supposed to clear the div's in the page or wot?
Calling document.write() after the page has finished loading will result
in a call to document.open(), which will clear the entire page content.
In some browsers, all script other than the one currently executing are
removed from memory immediately, in others they persist until the new
page is written but then are gone.

"clear the div's" is meaningless.

The pseudo code is here:

<html> <head>
...
<SCRIPT LANGUAGE="JavaScript">
The language attribute was deprecated many years ago, type is required.

...
[lots of code & functions including wholepage()]
...
function wholepage() {
document.write("<body bgcolor=\"#CCCCCC\">");
When you call wholepage(), the above statement will clear the entire
content of the current document. It appears that you don't write a new
title element, so you now have invalid HTML.

Your HTML uses deprecated attributes, you should look at updating to
HTML 4 - version 4.01 became a recommendation in 1999.

document.write("<div id=\"Layer1\" style=\"position:absolute;");
...[lots of code]
Presumably that 'lots of code' includes writing all the script elements
back into the document too.
document.write("</div> </body>");
You should always finish with:

document.close();

otherwise some browsers will wait forever for you to do so.

return true;}


What does it return true to?

[...]
--
Rob
Group FAQ: <URL:http://www.jibbering.com/faq/>
May 10 '06 #4
joe
RobG <rg***@iinet.net.au> wrote:
joe wrote:
I have a Javascript page which needs to be dynamically changed depending on user
input. The whole page is written on document.write() output.


That does not seem like a good idea. You should just modify the bits
that need to change, not re-write the entire page.

I am still new to Javascript and run into problems with page reload. When user
presses a button on my page most functions should clear the page and repaint it
using my wholepage() function. After a couple of repaint the page goes into some
error. Am I supposed to clear the div's in the page or wot?


Calling document.write() after the page has finished loading will result
in a call to document.open(), which will clear the entire page content.
In some browsers, all script other than the one currently executing are
removed from memory immediately, in others they persist until the new
page is written but then are gone.

"clear the div's" is meaningless.

I have a full sample here (below).
The page shows a "Hello" and "Press here". When user clicks the button at first
everything is OK. On second click IE shows "Error on page"
<SCRIPT LANGUAGE="JavaScript">
function mybutton(nap) {
window.alert("You pressed "+nap.toString());
wholepage();
return true; }

function wholepage() {
document.write("<html> <head>");
document.write("<title>Test page</title>");
document.write('<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1">');
document.write('<body bgcolor="#CCCCCC">');
document.write('<div id="Layer1" style="position:absolute; width:600px;
height:230px; left: 10px; top: 50px; z-index:1">');
document.write('<table width="590" border="1" height="172">');
document.write("<tr>");
document.write('<td height="25" width="404" bgcolor="#999999" colspan="2">');
document.write("Hello");
document.write('<input type="BUTTON" name="submit" value="Press here"
onClick="mybutton(1);">');
document.write("</td></tr>");
document.write("</table> </div> ");
document.write("</body></HEAD></html>");
document.close();
return true;}
</SCRIPT>

<SCRIPT LANGUAGE="JavaScript">
wholepage();
</SCRIPT>
May 10 '06 #5
joe wrote on 09 mei 2006 in comp.lang.javascript:


I have a full sample here (below).
The page shows a "Hello" and "Press here". When user clicks the button
at first everything is OK. On second click IE shows "Error on page"
<SCRIPT LANGUAGE="JavaScript">
use: <script type='text/javascript'>
function mybutton(nap) {
window.alert("You pressed "+nap.toString());
wholepage();
return true; }

function wholepage() {
document.write("<html> <head>");
document.write("<title>Test page</title>");


this cannot work, since after the first interactive document.write()
your javascript is overwritten and gone!!!!
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
May 10 '06 #6
ASM
joe a écrit :

I have a full sample here (below).
The page shows a "Hello" and "Press here". When user clicks the button at first
everything is OK. On second click IE shows "Error on page"


that can't work
and
that can't work

on second click function mybutton(nap) is unknown !

because
your document.write doesn't write the JS code for this function

--
Stephane Moriaux et son [moins] vieux Mac
May 10 '06 #7
joe
"Evertjan." <ex**************@interxnl.net> wrote:
joe wrote on 09 mei 2006 in comp.lang.javascript:


I have a full sample here (below).
The page shows a "Hello" and "Press here". When user clicks the button
at first everything is OK. On second click IE shows "Error on page"
<SCRIPT LANGUAGE="JavaScript">


use: <script type='text/javascript'>
function mybutton(nap) {
window.alert("You pressed "+nap.toString());
wholepage();
return true; }

function wholepage() {
document.write("<html> <head>");
document.write("<title>Test page</title>");


this cannot work, since after the first interactive document.write()
your javascript is overwritten and gone!!!!


How would my page be written then?
I thought the <script> - </script> part would stay in client memory.

May 10 '06 #8
joe wrote on 09 mei 2006 in comp.lang.javascript:
this cannot work, since after the first interactive document.write()
your javascript is overwritten and gone!!!!


How would my page be written then?
I thought the <script> - </script> part would stay in client memory.


where in memory?

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
May 10 '06 #9
ASM
joe a écrit :

How would my page be written then?
use an external javascript
it would be easier
I thought the <script> - </script> part would stay in client memory.


yes
except if you call a new page
and your javascript write a new page (or file)

this new page must have the same javascript written in it as the
original page
--
Stephane Moriaux et son [moins] vieux Mac
May 10 '06 #10
joe
ASM <st*********************@wanadoo.fr.invalid> wrote:
joe a écrit :

How would my page be written then?


use an external javascript
it would be easier
I thought the <script> - </script> part would stay in client memory.


yes
except if you call a new page
and your javascript write a new page (or file)

this new page must have the same javascript written in it as the
original page

I am used to writing C and Javascript is giving me grey hair! I can't see what is
wrong from a C programmers point of view.

What I am looking for is a page that can be somehow changed whether by repainting
the whole page or some part of it. How do I issue a reload without my variables
being reset?
May 10 '06 #11
ASM
joe a écrit :

I am used to writing C and Javascript is giving me grey hair! I can't see what is
wrong from a C programmers point of view.
I don't know C
I only know that your JS is forgotten when you document.write a new page
Your document.write has to be a part of your page.

I don't know how to tell it
see and try 2 examples bellow.
What I am looking for is a page that can be somehow changed whether by repainting
the whole page or some part of it. How do I issue a reload without my variables
being reset?


Exercise :

<html>
<script type="text/javascript">
function getIt() {
var u = self.location.search;
if(u && u.length>0) {
u = u.split('=')[1]
var f = document.forms[0].elements;
f[0].value = u;
}
else alert('no data to get');
}
function sendIt() {
var f = document.forms[0].elements;
var u = f[0].value;
if (u=='') {
alert('field is empty');
f[0].focus();
f[0].select()
return false;
}
else
f.action=self.location;
return true;
}
onload = getIt;
</script>
<form action="" method="get" onsubmit="return sendIt();">
<p>Put something here :
<input name="myData" type="text">
<input type="submit" value="GO">
</form>
</html>

Application in html with 'document.write' :

<html>
<script type="text/javascript">
function getIt() {
var u = self.location.search;
if(u && u.length>0) {
u = u.split('=')[1]
var f = document.forms[0].elements;
document.write('My new Data is : '+u);
}
else alert('no data to get');
}
function sendIt() {
var f = document.forms[0].elements;
var u = f[0].value;
if (u=='') {
alert('field is empty');
f[0].focus();
f[0].select()
return false;
}
else
f.action=self.location;
return true;
}
</script>
<form action="" method="get" onsubmit="return sendIt();">
<p>Put something here :
<input name="myData" type="text">
<input type="submit" value="GO">
</form>
<p>
<script type="text/javascript">
getIt();
</script>
</p>
</html>
--
Stephane Moriaux et son [moins] vieux Mac
May 10 '06 #12
joe wrote:
ASM <st*********************@wanadoo.fr.invalid> wrote:
joe a écrit :
How would my page be written then? use an external javascript
it would be easier
I thought the <script> - </script> part would stay in client memory.

yes
except if you call a new page
and your javascript write a new page (or file)

this new page must have the same javascript written in it as the
original page

I am used to writing C and Javascript is giving me grey hair! I can't see what is
wrong from a C programmers point of view.

What I am looking for is a page that can be somehow changed whether by repainting
the whole page or some part of it.


You need to learn about the basics of scripting web pages.

document.write is from the very beginning of JavaScript, there is no
public standard relating to how it should work. However, its behaviour
has been standardised to a large extent.

You can call document.write as the page loads to put content into the
page, however once the page has loaded (that is, the onload event has
occurred), a call to document.write will automatically also call
document.open.

Calling document.open opens a new document in the current window, which
is essentially the same as navigating to a new URL - everything in the
current page is deleted (ignoring caching, which is totally non-standard
and differs from browser to browser). The window object is also
deleted, it is a different entity to the browser window.

Scripts may hang around for a little while, but in most browsers will be
gone by the time the new document is displayed and certainly afterward -
objects and variables do not persist between documents (a pretty
fundamental principle).

Get your head around the document object model (DOM), because that is
what you are dealing with. From the point of view of JavaScript, the
browser is just a framework that supports the DOM.

How do I issue a reload without my variables
being reset?


You can't. You can store a small amount of data in cookies to use
between pages, but that is unreliable. You can also use XMLHttpRequest
and hidden iframes to load content from the server without loading a new
page, but that too can be unreliable (particularly support for
XHMHttpRequest when older browsers and mobile devices are taken into
consideration).

The usual idea for the web is to implement client/server data exchange
functionality using forms, then introduce script to speed things up and
replace form submission with XMLHttpRequest or to submit forms from
hidden iframes.

The best idea is to outline what you are trying to do from a
requirements perspective, show the code or test case you've developed to
implement it, then seek help here.
--
Rob
Group FAQ: <URL:http://www.jibbering.com/faq/>
May 10 '06 #13

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

Similar topics

4
by: David MacQuigg | last post by:
I'm going to be teaching EEs some basic Python using the first few chapters of Learning Python, 2nd ed. by Mark Lutz. The discussion on Reloading Modules starting on page 266 is confusing and I...
1
by: Cooper | last post by:
Hello, is possible to disable the reload (or update, for ie) of the a web page? If yes, what i do? Otherwise if isn't possible, what i do for to set the default value of a form when a user do a...
3
by: sentinel | last post by:
Hi all, I'm trying to reload a frame from a pop-up, but really cannot figure this out. Within my index.htm file, I make a link to call a pop-up frame with a javascript function that calls the...
19
by: Darren | last post by:
I have a page that opens a popup window and within the window, some databse info is submitted and the window closes. It then refreshes the original window using window.opener.location.reload(). ...
4
by: N. Demos | last post by:
Hello, I'm learning ASP.NET, and am having a strange problem with some example code from the book I'm using. The code increments and displays the value stored in a session variable when the "Add"...
7
by: fh | last post by:
hello! I 've a found way to reload my page automatically every n seconde using this code Response.AppendHeader("Refresh", "4"); it works fine but I wish to do the same with only a part of my...
8
by: T. Wintershoven | last post by:
Hi all, Is there a simple way in php to reload a page coded within an if statement.(see code below) It's very important that the session stays intact. The filename is RCStudent.php ...
2
by: Max | last post by:
Is it possible to reload a web page on user browser when an event occurs at server side? For example when user A places an order, user B should be notified of that and should see that order on his...
2
by: ericisjusteric | last post by:
I have a page with multiple iframes and need to have the user (ie6) be able to click a button to refresh any one of the iframes - but also to click another button at the top of the page to refresh...
14
by: =?Utf-8?B?UGF1bA==?= | last post by:
Hi I tried a google search but could not find anything. I am trying to cause one webpage to reload when a second web page is closed. The second webpage loads data into a session variable and when...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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
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,...

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.