title: HTML / JS - Calling a function from index.js onclick
body: <p>I want to call a function from within my index.js, in my functionality.js but because its linked to the browser I cant use import or require?</p>
  
  <p>I have an index.js, index.html and another functionality.js file. </p>
  
  <p>The functionality.js file is used by the index.html and within this file I 
  append some html under a specific circumstance and what I am trying to do is onclick call a function but call this function from my index.js file, which has to be there because it needs a socket.id.</p>
  
  <p>see here:</p>
  
  <p>*functionality.js: </p>
  
  <pre><code>$('#messages').append($('&lt;li id="messageclient"&gt;').append($(`
          &lt;div id="message-cont" class="message-cont"&gt;     
          &lt;div class="orderDetailsWrapper"&gt;
          &lt;div class="detailsHeaderWrapper"&gt;
              &lt;div class="orderNum"&gt;&lt;/div&gt;
              &lt;div class="customerName"&gt;&lt;/div&gt;
          &lt;/div&gt;
  
          &lt;div class="textToCustomer"&gt;
          &lt;p&gt; Please click on the item you want to return&lt;/p&gt;
  
         &lt;/div&gt;
  
          &lt;div class="itemBoxWrapper"&gt;
              &lt;div class="item1Wrapper" onclick="matchingResponse()"&gt;
                  &lt;div class="item1Title"&gt;&lt;/div&gt;
                  &lt;div class="item1Price"&gt;&lt;/div&gt;
              &lt;/div&gt;
  </code></pre>
  
  <p>*index.js</p>
  
  <pre><code>function matchingResponse() {
      var options = {
          method: 'POST',
          uri: 'https://dialogflow.googleapis.com/v2beta1/projects/returnsbot-50668/agent/sessions/1:detectIntent',
          headers: {
              'Authorization': `Bearer ${oAuthToken}`,
              'Content-Type': 'application/json'
          },
          body: {
              "queryInput": {
                  "event": {
                      "name": "Matching",
                      "languageCode": "en"
                  }
              }
          },
          json: true // Automatically stringifies the body to JSON
      };
      // initial message triggering.
      rp(options)
          .then(function (parsedBody) {
              console.log('DF response' + JSON.stringify(parsedBody))
              console.log('text ^^^^^^^^^^^^^^ ' + JSON.stringify(parsedBody.queryResul))
              text = parsedBody.queryResult.fulfillmentText;
  
              response = text;
              console.log('matching response +++++++++++' + text);
  
              data = [details.chatuser, response]
              io.of('/main').to(socket.id).emit('response', data);
  
          })
          .catch(function (err) {
              console.log(err);
          });
  }
  </code></pre>
  
  <p>Because the socket function is in the index.js file, I need this matchingresponse function inside of it to use the appropriate ID.</p>
  
  <p>Trouble is in functionality.js I can't use import / require.</p>
  
  <p>What can I do?</p>