Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can I keep this "onclick" from happening more than once?
    primarykey
    data
    text
    <p>I am trying to have a button, that when clicked, opens up an area to type a message. I am using "onclick" in the HTML and I want it to be only clickable once. I don't want it to keep making more textarea's the more you click it.</p> <p>I have a <em>this.onclick="null"</em> after the <em>onclick</em> that calls the function. This was working up until I added the submit button.</p> <p>So this code works:</p> <p>HTML:</p> <pre><code>&lt;html&gt; &lt;head&gt; &lt;script type="text/javascript" src="js/question.js"&gt;&lt;/script&gt; &lt;style type="text/css"&gt; #container { position: absolute; height: 443px; width: 743px; border: 1px solid black; border-radius: 0 0 20px 0; margin-top: 75px; } &lt;/style&gt; &lt;/head&gt; &lt;body&gt; &lt;div id="container"&gt;&lt;/div&gt; &lt;button id="new_message" onclick="createMessage(), this.onclick=null;"&gt;New Message&lt;/button&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>Javascript:</p> <pre><code>function createMessage() { var form = document.createElement("form"); form.name = "form_input"; form.method = "POST"; form.action = "messages.php"; container.appendChild(form); var textarea = document.createElement("textarea"); textarea.name = "message_input"; textarea.cols = 84; textarea.rows = 16; textarea.id = "message_input"; container.appendChild(textarea); }; </code></pre> <p>But when I leave the HTML the same and add the submit button to the javascript like this:</p> <pre><code>function createMessage() { var form = document.createElement("form"); form.name = "form_input"; form.method = "POST"; form.action = "messages.php"; container.appendChild(form); var textarea = document.createElement("textarea"); textarea.name = "message_input"; textarea.cols = 84; textarea.rows = 16; textarea.id = "message_input"; container.appendChild(textarea); var submit = document.createElement("button"); submit.innerHTML = 'Send'; submit.id = 'send_message'; container.appendChild(submit); submit.onClick(messageAjax()); }; </code></pre> <p>It starts to duplicate again. Is there any way to keep this from happining?</p> <p>Thanks for your help! </p>
    singulars
    1. This table or related slice is empty.
    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