Please Note This forum exists for community support for the Mango product family and the Radix IoT Platform. Although Radix IoT employees participate in this forum from time to time, there is no guarantee of a response to anything posted here, nor can Radix IoT, LLC guarantee the accuracy of any information expressed or conveyed. Specific project questions from customers with active support contracts are asked to send requests to support@radixiot.com.

Radix IoT Website Mango 3 Documentation Website Mango 4 Documentation Website

  • hi, i've seen code for a drop down selection box...

    http://mango.serotoninsoftware.com/forum/posts/list/598.page

    which i've been able to implement, but instead of numbers, i'd like text, which after selection, writes a corresponding numberic value to the point variable.

    what do i need to change?

    thanks

    Neil


  • Something like this... Change:

        s+= "<option value="+ i;
        if (value == i) { s+= " selected ";}
        s+= ">"+i+ "></option>";
    
    

    ... to:

    
        s+= "<option value=1>my label for 1</option>";
        s+= "<option value=2>my label for 2</option>";
        s+= "<option value=3>my label for 3</option>";
    
    

    ... and do what you need to do to default the selection (i.e. the "selected" attribute).


  • i've been fumbling.... and got this...

    var s="";
    s+="<select name='mode'"
    s+="onchange='mango.view.setPoint("+ point.id +", ""+ pointComponent.id +"", this.selectedIndex)'>'>"
    s+="<option value=0>local</option>"
    s+="<option value=1>remote</option>"
    s+="</select>";
    return s;

    whilst it works, unless the object selection is changed, the present value is not sync'd the real value..

    i saw the for loop in jokke example... but i ended up with 4 entries instead of 2...

    i tried to create a var called 'newval' and make that equal value (from the point value) and then modify the onchange to set a var, i.e. newval=this.selectedIndex

    an then at the end of the script update the mango.view.setpoint bit...

    couldn't get it to work though..

    also, if possible... might be nice to modify the whole thing so that a button [OK] 'onclick' causes the mango.view.setpoint bit to be updated, allowing the user to explore the choices for committing


  • Hello,

    It needs to have the "selected" in the option to be sync. The basic structure is this.

    
    <select onChange='somefunction()'>
    <option value=1 > one </option>
    <option value=2 selected > two </option>
    <option value=3 > three </option>
    </select>
    
    

    I used the loop to to write the selected into correct option (and not to write tens of times the same code)

    Here is an example without any loops.

    
    //Simple Select example
    var s="";
    
    s+="<select  onChange='mango.view.setPoint("+ point.id +", \""+ pointComponent.id +"\", this.options[this.selectedIndex].value )'>";
     
    s+= "<option value=1";
    if (value == 1 ) { s+= " selected ";}
    s+= "> one </option>";
    
    s+= "<option value=2";
    if (value == 2 ) { s+= " selected ";}
    s+= "> two </option>";
    
    s+= "<option value=3";
    if (value == 3 ) { s+= " selected ";}
    s+= "> three </option>";
    
    s+= "<option value=4";
    if (value == 4 ) { s+= " selected ";}
    s+= "> four </option>";
    
    s+="</select>";
    
    return s;
    
    
    

    I will put some more select examples from my views into the other topic.

    BR
    -Jokke