facebook

Noob Question about updating Combobox Values: CLOSED

💡
Our Forums Have Moved

For help with installation, bugs reports or feature requests, please head over to our new forums.
Genuitec Community on GitHub

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

    dannyg280
    Member

    I am a new MobiOne user and have limited javascript experience. So hopfully this a simple question:

    I have 2 Comboboxes, one called Category (cat) and one called Sub Category (subcat). I want the Sub Category box’s values to populate depending on which value is chosen in the Category box. I thought I had my code right but when I run it in Test Center, I must choose a category twice for it to work. In other words, nothing polulates in the Sub Category Box the first time I choose a category. Here is my code, which I entered into the “On Change…Run Javascript” action of the Category combobox:

    
    
    $category = $("select[name='cat']");
    $subcat = $("select[name='subcat']");
    
    $category.change(function() {
    
    if ($(this).val() == "FC") {
    $("select[name='subcat'] option").remove();
    $("<option>Neutral Floor Cleaner</option>").appendTo($subcat);
    $("<option>Heavy Duty Floor Cleaner</option>").appendTo($subcat);
    $("<option>Degreaser</option>").appendTo($subcat);
    }
    
    if ($(this).val() == "SC") 
    {
    $("select[name='subcat'] option").remove();
    $("<option>All Purpose Cleaner</option>").appendTo($subcat);
    $("<option>HD Spray Cleaner</option>").appendTo($subcat);
    $("<option>Peroxide Cleaner</option>").appendTo($subcat);
    }
    
    if ($(this).val() == "DIS") 
    {
    $("select[name='subcat'] option").remove();
    $("<option>Neutral Disinfectant</option>").appendTo($subcat);
    $("<option>Alkaline Disinfectant</option>").appendTo($subcat);
    $("<option>Frag-Free Disinfectant</option>").appendTo($subcat);
    }
    
    
    
    });
    

    Any help would be greatly appreciated!

    #341509

    Hi dannyg280,

    You can try calling the phoneui.preprocessDOM after populating your combobox to refresh the data:

    phoneui.preprocessDOM('#m1-<screenID>');

    or

    phoneui.preprocessDOM(phoneui.getCurrentPageId());

    You can also take a look at this example provided by dev team that demonstrate how to populate a combobox: http://portal.genuitec.com/support-genuitec/viewtopic.php?p=18229#p18229

    And here is another topic where a similar question was responded: http://www.genuitec.com/support-genuitec/viewtopic.php?p=12785#p12785

    #341511

    dannyg280
    Member

    Thank you so much for your response. I apologize for being so new at this but I can’t seem to get either of those options to work. I’m attaching my MobiOne files hoping you can tell me where I went wrong. I feel like I must not be calling the correct screenID? I’m not sure.

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

    Hi dannyg280,

    Seems that the problem wasn’t that the use of phoneui.preprocessDOM() function. In the code you don’t need to add the event, since it’s being created by Mobione, please try next code:

    
    $subcat = $("select[name='subcat']");
    
    if ($(this).val() == "FC") {
    $("select[name='subcat'] option").remove();
    $("<option>Neutral Floor Cleaner</option>").appendTo($subcat);
    $("<option>Heavy Duty Floor Cleaner</option>").appendTo($subcat);
    $("<option>Degreaser</option>").appendTo($subcat);
    }
    
    if ($(this).val() == "SC") 
    {
    $("select[name='subcat'] option").remove();
    $("<option>All Purpose Cleaner</option>").appendTo($subcat);
    $("<option>HD Spray Cleaner</option>").appendTo($subcat);
    $("<option>Peroxide Cleaner</option>").appendTo($subcat);
    }
    
    if ($(this).val() == "DIS") 
    {
    $("select[name='subcat'] option").remove();
    $("<option>Neutral Disinfectant</option>").appendTo($subcat);
    $("<option>Alkaline Disinfectant</option>").appendTo($subcat);
    $("<option>Frag-Free Disinfectant</option>").appendTo($subcat);
    }
    
    phoneui.preprocessDOM('#m1-GCC');

    Let us know how it goes.

    #341543

    dannyg280
    Member

    Octavio- Thank you!! Worked perfectly! I’m now on my 2nd day of my MobiOne trial and I’m loving it! To get free, helpful support without criticism on a newbie question is almost unheard of. I almost certainly will be purchasing a license and be recommending it to friends.

    Thanks Again

    Dan

    #341549

    dannyg280
    Member

    One more quick question. That works great and if I understand it right, it will populate the Combobox with options with no values… Can you tell me the correct syntax to have it populate both an option and a value? I tried the code below but it doesn’t seem to be working, it actually breaks the original code and the box does not populate at all.

    
    $("<option value="NFC">Neutral Floor Cleaner</option>").appendTo($subcat);
    
    #341555

    Hi,

    I followed the example I shared in a previous post, and with this code, it works fine:

    $("<option />").val("Neutral Floor Cleaner").text("Neutral Floor Cleaner").appendTo($subcat);
    #341561

    dannyg280
    Member

    Once again, thank you! Worked perfectly!

    #341564

    Hi dannyg280,

    Thanks for the follow up. Glad to help. Marking thread as closed.

Viewing 9 posts - 1 through 9 (of 9 total)
Reply To: Noob Question about updating Combobox Values: CLOSED

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