B4J Question WebSocket - Run Sub from HTML Function

Discussion in 'B4J Questions' started by aaronk, Jul 16, 2015.

  1. aaronk

    aaronk Well-Known Member Licensed User


    I am using WebSockets in my B4J app and I am trying to work out how to trigger a sub in my B4J project from a HTML page function.

    Looking though the tutorial you need to put a sub in the B4J app like:

    Sub btnCalc_Click (Params As Map)
    "Hello World")
    End Sub
    And using a button in the HTML page:
    <!DOCTYPE html>
    <html xmlns="http://www.w3.org/1999/xhtml">
    <title>Web App Hello World!</title>
      <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>
      <link rel="stylesheet" type="text/css" href="index.css" />
      <script src="/b4j_ws.js"></script>
      <h1>Web App Hello World!</h1>
      <p id="plog"></p>
      <div id="maindiv">
      First Number: <input id="text1" type="text"></input><br/>
      Second Number: <input id="text2" type="text"></input><br/>
      <button id="btncalc">Calculate</button><br/>
      <p id="result"></p>
      //connect to the web socket when the page is ready.
      $( document ).ready(function() {
    Everything is working fine so far..

    But rather than using a button to trigger the code in the B4J app (btnCalc_Click) is there a way to run the sub in the B4J from a function in the HTML page ?

    <button onClick="RunFunction();">Click Me</button>
    function RunFunction()
        // What code can I use here to run the Sub in my B4J app?
  2. billzhan

    billzhan Active Member Licensed User


    function RunFunction()
    "btnCalc_Click", {}) ;
  3. aaronk

    aaronk Well-Known Member Licensed User

    That did the job.
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice