Search code examples
javascripthtmlpandorabots

Calling many functions in one HTML tag


The following code for a browser chat works as a whole, but it's not neat.

<p>chat in silence:</p>
<input id="yousay" name="input" size="52" onkeydown="if (event.keyCode == 13) { doTalk(); }"/>

<p>chat in with music:</p>
 <textarea onfocus="clearContents(this);" id="chat" cols="50" rows="2" ></textarea>

 <button type="button" onclick="triggerAll();">answer</button>

these are the scripts:

<script src="scripts/soundEngine.js"></script>
<script src="scripts/animationEngine.js"></script> 
<script src="scripts/talk.js"></script>

this calls the bot API

<script>
  var pb = new Pandorabot("aiaas.pandorabots.com", 'validid', 'validname', 'validid'); 
  function doTalk() {
    var input = document.getElementById("yousay").value;
    document.getElementById("yousay").value = "";
    pb.talk(input, function(data) {
      var response = data["responses"];
      document.getElementById("response").innerHTML = response;
      console.log(response);
    });
  }
</script>

and this a function to call them all at once:

<script>
      function triggerAll(){
        doTalk();
        play_song();
        animate_song();
      }
</script>

Apparently, <textarea> calls play_song() and animate_song(), but does not call doTalk()

Is there a way I can put all function calls within one tag and reduce the code?


Solution

  • In html you can call function that calls all of them. Like you have script one,two,three and you do this

    <randomtag onclick="call_all()"></randomtag>
    
    <script type="text/javascript">
      function call_all(){
        one();
        two();
        three();
      }
    </script>