Search code examples
airconsole

Send form data from controller to screen on AirConsole


If i have a form with 3 differents textfields on controller.html, it's possible to send the data of the 3 elements with a "send button" to my screen?


Solution

  • Sending a form would basically work the same as you would do it the usual way in javascript:

    1. Catch the form submission via the onsubmit event

    2. Get the input values and send them via airconsole.message

    Something like this:

        var form_ele = document.getElementById("form");
    
        form_ele.addEventListener('submit', function(e) {
            e.preventDefault();
            var input_1_val = your_input_element.value;
            airconsole.message(AirConsole.SCREEN, { 
                input_1: input_1_val,
                // other key values
            };
        });
    

    An AirConsole controller is nothing else than a (mobile) website.