Note that there are some explanatory texts on larger screens.

plurals
  1. POSelf defined Javascript function not working as I expected?
    primarykey
    data
    text
    <p>I had developed a LOGO-like basic turtle graphics interpreter a few years back, I wan't to put it on the web (as my cousin keeps bugging me for it). Though I am quite new to HTML, Javascript coding I thought I would give it a try &amp; take this as a learning experience.</p> <p>The below code is just for the basic UI (my UI looks very ugly and I will clean it up later).</p> <p>I have written a Javascript function pushCmd which is called onsubmit of the "cmd-form".</p> <pre><code>function pushCmd() { var cmdText = document.forms["cmd-form"]["cmd-text"].value; var srcElement = document.getElementById("source-container"); var srcText = new String(srcElement.innerHTML); srcText = srcText.toUpperCase(); if (srcText.indexOf("NO CODE") != 0) { srcText = cmdText; } else { srcText += "&lt;br&gt;" + cmdText; } srcElement.innerHTML = srcText; } </code></pre> <p>The form is declared like below.</p> <pre><code>&lt;div id="command-container"&gt; &lt;form name="cmd-form" action="" onsubmit="pushCmd()" onreset="resetSource()" method="post"&gt; &lt;input type="text" name="cmd-text" size="80"&gt; &lt;input type="submit" value="Send"&gt; &lt;input type="reset" value="Reset"&gt; &lt;input type="button" value="Run"&gt; &lt;/form&gt; &lt;/div&gt; </code></pre> <p>The pushCmd function should alter the HTML content of the div "source-container" which by default looks like below.</p> <pre><code>&lt;div id="source-container"&gt;NO CODE&lt;/div&gt; </code></pre> <p>After I submit the first text (say "FWD 100"). The content of the "source-container" should change to "FWD 100". Then If I submit "RT 90", the content should be "FWD 100<br>RT 90". This is what I expect out of it.</p> <p>But when I submit the text. The content of the "source-container" changes for just an instant and then again comes back to "NO CODE". Why is this happening, can anyone please point out where my mistake lies? </p> <p>I tried both get &amp; post methods but the result is the same. I cannot see any errors or warnings in the Javascript console either. I am using Google chrome Version 26.0.1410.63 if that matters (I guess not).</p> <p>Please let me know if you need any further information or the full HTML source for this. </p>
    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