1

I am trying to load an external javascript from a html input button. However when I click on the button I get no output or response. I do get a message in console that the script has been loaded though. HTML:

<div class="split left">
    <fieldset class="Receiver Commands">
        <legend>Receiver Commands</legend>
<input type="button" value="click me" id="clickMe" onclick="serverStart()" />
        <script type="text/javascript" src="{%static 'scripts/ServerResponse.js' %}">
    </script>
            <form method="post">
            </form>
        <div id="testtaskbox" class="testtaskbox">
        {% csrf_token %}

        </div>
    </fieldset>
    <fieldset class="receiverResponse">
        <legend>Receiver Response</legend>
        <div class="receiverText">
            <textarea id ="response" class="textarea">Digdebugv2 1.11
                {{responseContext}}
            </textarea>
        </div>
    </fieldset>
</div>

Javascript:

serverStart()
function serverStart () {
  document.getElementById('reponse').innerHTML = '123bob'
  console.log('ServerResponse started')
}
2
  • Check console for error Commented Nov 26, 2018 at 11:25
  • Maybe the problem is that you are trying to get reponse instead of response when your are using getElementById. Commented Nov 26, 2018 at 11:25

1 Answer 1

1

Your document.getElementById('reponse').innerHTML = '123bob' 'response' was not correct spelled.

Replace your current code with this and it will work.

 function serverStart () {
  document.getElementById('response').innerHTML = '123bob'
  console.log('ServerResponse started')
}
serverStart();
    <div class="split left">
    	<fieldset class="Receiver Commands">
    		<legend>Receiver Commands</legend>
    <input type="button" value="click me" id="clickMe" onclick="serverStart()" />
    		<script type="text/javascript" src="{%static 'scripts/ServerResponse.js' %}">
    	</script>
    			<form method="post">
    			</form>
    		<div id="testtaskbox" class="testtaskbox">
    		{% csrf_token %}
    
    		</div>
    	</fieldset>
    	<fieldset class="receiverResponse">
    		<legend>Receiver Response</legend>
    		<div class="receiverText">
    			<textarea id ="response" class="textarea">Digdebugv2 1.11
    				{{responseContext}}
    			</textarea>
    		</div>
    	</fieldset>
    </div>

Sign up to request clarification or add additional context in comments.

2 Comments

oh my god, im an idiot. been looking at this for hours, thank you!
no problem. please set question as answered. that way everyone knows the question is answered. @Callum

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.