473,327 Members | 2,112 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,327 software developers and data experts.

document.write

Hallo!

Könnt ihr mir sagen, wie document.write genau funktioniert und warum es
solch gewaltige Unterschiede in der Interpretation bei Browsern gibt?

Ich habe heute vielleicht eine Dreiviertelstunde lang mit einem Programm
gekämpft. Es ist ein ganz simples JavaScript-Programm mit einem Formular,
welches einen Button enthält, über den eine Funktion aufgerufen wird. Die
gewünschte Ausgabe mit alert() funktioniert wunderbar, aber document.write()
macht bei manchen Browsern Schwierigkeiten. Dort lief es auf Windows, auf
Mac versagte es aber seinen Dienst und gab eine unerklärliche Fehlermeldung
aus, das array "punkt" sei nicht bekannt.

Hoffe auf ein wenig Klarheit.

Gruß
Alexander

---------------

<html>
<head><title> Alexander Erlich A2</title>
<script language ="JavaScript" type="text/javascript">

var namen=new
Array("Anne","Berta","Claudia","Dora","Erika","Fri eda","Gerda","Hanna","Ina","Jana");
var punkt=new Array(8,1,15,3,12,8,3,7,5,9);
function ausgabe() {
var i;
var counter=0;
var eingabe = window.document.klausur.punktangabe.value;
eingabe = parseInt(eingabe);
alert (eingabe);

for (i=0; i<punkt.length; i++) {
if (punkt[i] == eingabe) {
//alert(namen[i] + "<br>");
document.write (namen[i] + "<br>") // !
counter++;
}
}

document.write ("Es gibt " + counter + " Teilnehmer mit " + eingabe + "
Punkten.<br> ");

}

</script>
</head>
<body>
<h1> Klausurergebnis </h1>
<form name="klausur">
<br><br> Gib hier die Punktzahl an, f&uuml;r die du die Teilnehmer
suchst:
<input type="text" name="punktangabe" value=3>
<input type="button" name="aus" value="Ausgeben" onClick="ausgabe();">
</form>
</body>
</html>
Jul 23 '05 #1
1 3028
Alexander Erlich wrote:
Könnt ihr mir sagen, wie document.write genau funktioniert und warum
es solch gewaltige Unterschiede in der Interpretation bei Browsern
gibt?


When you call document.write() when the initial output is generated, it
overwrites the output completely, including JavaScript declarations.

For what you want to do, it is best to use
document.getElementID(id).innerHTML as follows:

In function ausgabe():

var html = '';
for (i = 0; i < punkt.length; i++) {
if (punkt[i] == eingabe) {
html += namen[i] + "<br>";
counter++;
}
}
html += "Es gibt " + counter + " Teilnehmer mit " + eingabe + "
Punkten.<br> ";
document.getElementByID('result').innerHTML = html;

And in the HTML:

<h1> Klausurergebnis </h1>
<div id="result"> </div>
<form name="klausur">
....
JW

Jul 23 '05 #2

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

Similar topics

1
by: techy techno | last post by:
Hii Just wanted to know how can I decorate my texboxes and Listmenu which is called from a JS file using the following code below: document.write("<SELECT NAME='cur2' ONCHANGE='cconv1();'>");...
2
by: Brett Baisley | last post by:
Hello I have a block of html code that I want to run by calling a javascript function to print it. Its basically a table with menu items in it that is the same for many pages, and instead of...
14
by: Eli | last post by:
I've got a script that I'm trying to debug which uses document.write() to place HTML within a page. In both IE6 and Firefox when I view source, I see only the script itself and not any HTML as...
4
by: Prowler | last post by:
In the application we are currently building, we need to write positioning code on-the-fly, based upon the screen offset of the element in the AS/400 application which drives the Web app. The 400,...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.