Note that there are some explanatory texts on larger screens.

plurals
  1. POJavascript onclick
    primarykey
    data
    text
    <p>I'm having a problem with javascript. I'm trying to create a button that will cause some content to load over on top of what I got. I created some functions to do this. It works perfectly if I test the function on the HTML page if the script is already loaded, however, when I use an onclick event to call the function, it just creates an entirely new .html page with the content in it.</p> <p>I know this because I saved the page it created, then I viewed the source, and it was just a blank page with the contents of the javascript function written in the body tag.</p> <p>Here is the HTML.</p> <pre><code> &lt;ul class="sub-menu"&gt; &lt;li onclick='articleRead("test", DeviantArtUpdateContent)'&gt;&lt;a href="#Deviant Art Update"&gt;Deviant Art Update&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="#"&gt;'Triumph At Last' Album Preview&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="#"&gt;Short Funny and Stupid&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="#"&gt;Project Preview&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt; &lt;div id="aID"&gt;&lt;/div&gt; </code></pre> <p>Here is the javascript.</p> <pre><code>function articlePopUp ( title , content) { document.write('&lt;div class="backgroundFade"&gt;&lt;/div&gt;'); document.write('&lt;div class="articlePosition"&gt;&lt;div class="closeArticle"&gt;Close&lt;/div&gt;'); document.write('&lt;div class="articleRead"&gt;'); document.write('&lt;h1&gt;'); document.write(title); document.write('&lt;/h1&gt;'); document.write('&lt;div class="grey-line"&gt;&lt;/div&gt;'); document.write(content); document.write('&lt;/div&gt;&lt;/div&gt;'); } function articleRead ( title, content) { document.getElementById("aID").innerHTML=articlePopUp(title,content); } </code></pre> <p>Like I said before, if I just call the function in the HTML document without an onclick event it works the way I intended, but adding the onclick event creates a blank document when I click it. I want to write the function into the existing document in the intended div id. Thanks ofr any help in advance, this really gots me stumped.</p>
    singulars
    1. This table or related slice is empty.
    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.
    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