facebook

Dynamic selection in ‘Select List Menu’ : CLOSED

  1. MobiOne Archive
  2.  > 
  3. Getting Help – General
Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #342832 Reply

    hussain.m
    Member

    Hi,

    I want to dynamically select from one of the options in my select list when a button is clicked. I also want the new option selected in the select list menu to be displayed on the screen. So the old label should not be shown as selected anymore after button is pressed. Instead, the new label shown be shown.

    I can retrieve the value of the current selection by:
    var selection1 = $(‘select[name=”selectListMenu1″]’).val();

    But what is the code for setting a different value and displaying the corresponding label for it on the screen?

    Please let me with the JavaScript code for this.
    Thank you.

    #342880 Reply

    hussain.m
    Member

    Please can anyone help? It’s urgent.
    Thank you.

    #342890 Reply

    Hi hussain.m,

    You can achieve it creating the next function in your custom.js file.

    function selectItem(item){
      var selListId = 'm1-testSelect-list1';
      var listName = 'list1';
    
      var itemToSelect = item;
    
      var selId = $('#' + selListId + '> li').each(
      function (i) {
        $(this)[i == itemToSelect ? 'addClass' : 'removeClass'](m1Design.css("selected"));
      });
    
      // This line updates hidden select, for the case the whole 
      // design will be used as a form
      phoneui.preprocessDOM('#' + selListId);
      
    }

    Then, call it in your button sending the parameter of the item you want to select:

    selectItem(1);

    Note that first item in list will be 0, so, with this example you’ll be selecting the second item on the list.

    #342925 Reply

    hussain.m
    Member

    I tried your code but it is not working. When I press the button, nothing happens.
    I am using Select List Menu with List Display Mode set as Spinner.

    I plugged in my variable as below:

    var selListId = ‘m1-Untitled1-list1’;
    var listName = ‘selectListMenu1’;

    Please let me know how to fix this.
    Thank you.

    #342954 Reply

    Hi hussain.m,

    Disregard my last reply, I thought you were looking select an item in a select list item. Please take a look at next sample file that meet the requirement you have requested.

    Attachments:
    You must be logged in to view attached files.
    #342969 Reply

    hussain.m
    Member

    Thanks for your reply.

    This code works for the Select List Menu when the ‘Item Display Mode’ is set to “Select List”. It does not work when I change it to “Spinner”. Can you send me code for “Spinner” Item Display Mode??

    #342992 Reply

    Hi hussain.m,

    Seems that the third try is the good one. See attached example.

    Attachments:
    You must be logged in to view attached files.
    #343027 Reply

    hussain.m
    Member

    Works perfectly! 🙂
    Thank you.

Viewing 8 posts - 1 through 8 (of 8 total)
Reply To: Dynamic selection in ‘Select List Menu’ : CLOSED

You must be logged in to post in the forum log in