473,651 Members | 2,644 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 Dreiviertelstun de 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","B erta","Claudia" ,"Dora","Erika" ,"Frieda","Gerd a","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.punkta ngabe.value;
eingabe = parseInt(eingab e);
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="punktanga be" value=3>
<input type="button" name="aus" value="Ausgeben " onClick="ausgab e();">
</form>
</body>
</html>
Jul 23 '05 #1
1 3054
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.getEle mentID(id).inne rHTML 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.getEle mentByID('resul t').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
2868
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();'>"); document.write("<OPTION VALUE='0.345066110642241'>Argentina Peso </OPTION>"); document.write("<OPTION VALUE='0.790200069503053'>Australia Dollar
2
2379
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 copying/pasting everytime I change it, I figure this will be better, as I only change it once. The problem is, document.write doesn't handle multiple lines very well, so I was wondering what is the best way to do this? Maybe there is even a better...
14
4110
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 it's being written into the page. Is there a way that I can view what is being placed into the page, instead of, or in addition to the javascript code?
4
2944
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, like DOS, uses memory-mapped display, two bytes per character (one char byte and one attribute byte). We can get the screen offset allright, and I've written a javascript which does the math to convert the offset into row/col (i.e. left, top)...
0
8349
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
1
8460
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8576
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7296
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6157
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5609
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4143
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2696
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1585
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.