CPFB | Information (2024)

'); // Insert a styled div to sit over the top of the hidden select element $this.after('

'); // Cache the styled div var $styledSelect = $this.next('div.styledSelect'); // Show the first select option in the styled div $styledSelect.text($this.children('option').eq(0).text()); // Insert an unordered list after the styled div and also cache the list var $list = $('

    ', { 'class': 'options' }).insertAfter($styledSelect); // Insert a list item into the unordered list for each select option for (var i = 0; i < numberOfOptions; i++) { $('

  • ', { text: $this.children('option').eq(i).text(), rel: $this.children('option').eq(i).val() }).appendTo($list); } // Cache the list items var $listItems = $list.children('li'); // Show the unordered list when the styled div is clicked (also hides it if the div is clicked again) $styledSelect.click(function (e) { e.stopPropagation(); $('div.styledSelect.active').each(function () { $(this).removeClass('active').next('ul.options').hide(); }); $(this).toggleClass('active').next('ul.options').toggle(); }); // Hides the unordered list when a list item is clicked and updates the styled div to show the selected list item // Updates the select element to have the value of the equivalent option var previousvalue = 'Search Within CPF Website'; $listItems.click(function (e) { e.stopPropagation(); $styledSelect.text($(this).text()).removeClass('active'); $this.val($(this).attr('rel')); //alert($(this).attr('rel') == $('#selectsearch').val() ? true : false); $list.hide(); if ($(this).attr('rel') == previousvalue) { return; } previousvalue = $(this).attr('rel'); var CMSBasePlaceholderDefaultText = 'Search Within CPF Website'; var CMSBasePlaceholderAllGovText = 'Search Within All Singapore Gov Websites'; $('#txtSearch2').attr('placeholder', $(this).attr('rel')); if ($('#txtSearch2').val() && $('#txtSearch2').val() != CMSBasePlaceholderDefaultText && $('#txtSearch2').val() != CMSBasePlaceholderAllGovText) { Search(); } else { $('#txtSearch2').val($('#txtSearch2').attr('placeholder')) } /* alert($this.val()); Uncomment this for demonstration! */ }); $listItems.hover(function (e) { e.stopPropagation(); $styledSelect.text($(this).text()).removeClass('active'); $this.val($(this).attr('rel')); $('#txtSearch2').attr('placeholder', $(this).attr('rel')); /* alert($this.val()); Uncomment this for demonstration! */ }); // Hides the unordered list when clicking outside of it $(document).click(function () { $styledSelect.removeClass('active'); $list.hide(); }); });

  • CPFB  | Information (2024)
    Top Articles
    Latest Posts
    Article information

    Author: Eusebia Nader

    Last Updated:

    Views: 5725

    Rating: 5 / 5 (80 voted)

    Reviews: 95% of readers found this page helpful

    Author information

    Name: Eusebia Nader

    Birthday: 1994-11-11

    Address: Apt. 721 977 Ebert Meadows, Jereville, GA 73618-6603

    Phone: +2316203969400

    Job: International Farming Consultant

    Hobby: Reading, Photography, Shooting, Singing, Magic, Kayaking, Mushroom hunting

    Introduction: My name is Eusebia Nader, I am a encouraging, brainy, lively, nice, famous, healthy, clever person who loves writing and wants to share my knowledge and understanding with you.