Jump to content

  • You cannot start a new topic
  • You cannot reply to this topic

Changing The Selected Item In A Select Box Rate Topic   - - - - -

 

Posted 08 April 2021 - 12:45 PM #1

I am adding logic to a product to hide an option and reshow it based on some choices.  However, after I hide and reshow, my textbox has an extra item added and selected "Please, select one".  Either, how can I get rid of that option, or how can I change the option to the first variant defined in the product?  Here is my code, which I inherited from a previous developer (open to suggestions on how to do this better):

 

         var cover_labels = $("#op_option_pages").find("label:contains('Scratch and Dent')");
            var cover_label = null;
            for(var i=0, len = cover_labels.length; i<len; i++) {
                if(cover_labels.eq(i).text().length <= 18) {
                    cover_label = cover_labels.eq(i);
                    break;
                }
            }
            if(cover_label) {
                var cover_page = cover_label.closest('.op-page');
                var cover_option = cover_page.find('#' + cover_label.attr('for') + ' option:selected');
                if(cover_option.length) {
                    var cover_text = cover_option.text();
                    if(displayscratchanddent.indexOf("false") > -1)
                    {
                        cover_label.closest('.op-page-option').remove();
                    }
                    else
                    {
                        cover_label.addClass();
                    }
                }
            }