/ Published in: JavaScript

Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
/* This function sets the combobox with the value after "like" inside the url */ (function($) { //get the url variables and set the combo box var comboBox = $(location).attr('href'); comboBox = decodeURIComponent(comboBox); //decode url string comboBox = comboBox.replace(/"/g, ''); //replace quotes var urlArray = comboBox.split("+"); //get params //the param we're looking for is after "like" comboBox = urlArray[jQuery.inArray("like", urlArray)+1]; $('#combobox-id > option').each(function(index) { //alert($(this).text() + ' ' + $(this).val()); console.log(index + " " + $(this).attr('value')); if ($(this).attr('value') === comboBox) { comboBox = index; } }); $('#combobox-id').attr('selectedIndex', jQuery.inArray(comboBox, urlArray));
URL: http://www.jquery4u.com/snippets/dynamically-combobox-value-url/
Comments
