0

Javascript Read user Variable

How can I put a user variable in to a javascript variable
Thx

5 comments

  • 0
    Avatar
    Bright Scripters

    Here’s a way using the BrightSign unit webserver and user variables feature:

    1. Add variables in BrightAuthor

    2. In your JS use getUserVars (HTML attached). This will get the variable from the user variables on the unit.

    3. To put back to the unit use a from element (populate this in the background) and use ‘SetValues’ to post back to the database – i.e. “form id="main" action="/SetValues" method="post">. You could do this with a setInterval() to update the database as needed.

    Here’s some pseudo code for posting back to the database:

    function doUserVars(us) 
    {
      printObj(us)
    
      if(typeof us === 'undefined') 
      {
        console.log("userVars not defined"); 
          setTimeout(function(){getUserVars(doUserVars)},1000);
        return; 
      }
    
    var str='<form id="main" action="/SetValues" method="post">'; 
    $.each(us,function(){
      str+=this.key+':<br/><input class="bs_input" type="text" name="'+this.key+'" 
    value="'+this.value+'"/><br/>'; });
      str+='<br/><input id="button" type="hidden" value="Submit Cities"/></form>'; 
        $('div.varform').html(str);
    }
    
    function formsubmit(){
       $("#main").submit()
    }
  • 0
    Avatar
    Patrik Friedrich
    Thank you very much.
    Unfortunately that script does not work. I get Errors.
     
     
     

    <script>

    function getUserVars(callback){
     console.log("getUserVars");
     sUrl="http://localhost:8080/GetUserVars";

     $.get(sUrl,function(data,status,jqXHR){
      un=jqXHR.responseText;
      xmlDoc = $.parseXML( un );
      $xml = $( xmlDoc );
      console.log(un);
      console.log("fetching variables...")

     $xml.find('BrightSignVar').each(function(){
      var name = $(this).attr('name')
      console.log(name);
     
     switch (name) {
      case "volume":
       var volume = $(this).text(); break;

     $('#name').html(mmaker);

    </script>

  • 0
    Avatar
    Bright Scripters

    I never said it works :)

    What isn't working for you?

    If you shared the console.log() output at the various stages, we could try and help.

  • 0
    Avatar
    Stefan

    I too cant get this working since upgrading from a series 3 to series 4 Player. Do you have a working presentation you could Share?

  • 0
    Avatar
    Bright Scripters

    Use of the Javascript console might be helpful.

    I'm no expert in Javascript, but I'm pretty sure the code above is incomplete.

    There are open braces, without matching closing braces, such as the switch statement.

Please sign in to leave a comment.