Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The basic problem is how you pass your arguments to handleContent. The href="" currently doesn't do anything. the solution is to pass "topright" or "bottomright" via a closure. That works like this:</p> <pre><code>(function (t){ return function(){ handleContent(t); } })(target); </code></pre> <p>This creates a function that is directly called and returns a function which "bound" your argument (this is called a closure).</p> <p>As I think your german: Du musst dafür sorgen das deine Argumente richtig übertragen werden. Das machst du am einfachsten mit einem sogenannten Closure (eine Funktion die deinen Parameter in sich selbst speichert).</p> <p>Solution (Tested in Firefox):</p> <pre><code>&lt;body&gt; &lt;div id="left"&gt; &lt;p&gt;&lt;a name = "container" value="topright" onclick="loadContent('hallo1.php', 'topright');"&gt;Hallo Welt 1&lt;/a&gt;&lt;/p&gt; &lt;p&gt;&lt;a name = "container" value="bottomright" onclick="loadContent('hallo2.php', 'bottomright');"&gt;Hallo Welt 2&lt;/a&gt;&lt;/p&gt; &lt;/div&gt; &lt;div id="topright"&gt;&lt;/div&gt; &lt;div id="bottomright"&gt;&lt;/div&gt; &lt;script&gt; var xmlHttpObject = false; if (typeof XMLHttpRequest != 'undefined') { xmlHttpObject = new XMLHttpRequest(); } if (!xmlHttpObject) { try { xmlHttpObject = new ActiveXObject("Msxml2.XMLHTTP"); } catch(e) { try { xmlHttpObject = new ActiveXObject("Microsoft.XMLHTTP"); } catch(e) { xmlHttpObject = null; } } } function loadContent(id, target){ xmlHttpObject.open('get', id); xmlHttpObject.onreadystatechange = (function(t){return function(){ return handleContent(t);}})(target); xmlHttpObject.send(null); return false; } function handleContent(target){ if (xmlHttpObject.readyState == 4) { document.getElementById(target).innerHTML = xmlHttpObject.responseText; } } &lt;/script&gt; &lt;/body&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload