Using $index with the AngularJS ‘ng-options’ directive?

Since arrays are very similar to objects in JavaScript, you can use the syntax for “object data sources”. The trick is in the brackets in the ng-options part: var choices = [ ‘One’, ‘Two’, ‘Three’ ]; In the template: <select ng-model=”model.choice” ng-options=”idx as choice for (idx, choice) in choices”> </select> In the end, model.choice will … Read more

Setting the selected attribute on a select list using jQuery

If you don’t mind modifying your HTML a little to include the value attribute of the options, you can significantly reduce the code necessary to do this: <option>B</option> to <option value=”B”>B</option> This will be helpful when you want to do something like: <option value=”IL”>Illinois</option> With that, the follow jQuery will make the change: $(“select option[value=”B”]”).attr(“selected”,”selected”); … Read more

jQuery – disable selected options

Add this line to your change event handler $(“#theSelect option:selected”).attr(‘disabled’,’disabled’) .siblings().removeAttr(‘disabled’); This will disable the selected option, and enable any previously disabled options. EDIT: If you did not want to re-enable the previous ones, just remove this part of the line: .siblings().removeAttr(‘disabled’); EDIT: http://jsfiddle.net/pd5Nk/1/ To re-enable when you click remove, add this to your click … Read more

Setting hidden datalist option values

You can use data-value and jquery to make your value hidden. e.g: $(document).ready(function() { $(‘#submit’).click(function() { var value = $(‘#selected’).val(); alert($(‘#browsers [value=”‘ + value + ‘”]’).data(‘value’)); }); }); <script src=”https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js”></script> <input id=”selected” list=”browsers” name=”browser”> <datalist id=”browsers”> <option data-value=”1″ value=”InternetExplorer”></option> <option data-value=”2″ value=”Firefox”></option> <option data-value=”3″ value=”Chrome”></option> </datalist> <input id=”submit” type=”submit”> jsfiddle Thanks to @guest271314

Image in SELECT element [duplicate]

Doing this in a cross-browser way is going to be very challenging, and I suspect, impossible. Instead, you might want to try using a widget that looks and acts like a select box, but is made w/ HTML & Javascript. Here’s one way to do it with jQuery: jquery.combobox

Editable ‘Select’ element

Nothing is impossible. Here’s a solution that simply sets the value of a text input whenever the value of the <select> changes (rendering has been tested on Firefox and Google Chrome): .select-editable {position:relative; background-color:white; border:solid grey 1px; width:120px; height:18px;} .select-editable select {position:absolute; top:0px; left:0px; font-size:14px; border:none; width:120px; margin:0;} .select-editable input {position:absolute; top:0px; left:0px; width:100px; padding:1px; … Read more

Selecting options using Selenium and Python

To select the select-options with text as CSV from the html-select tag using Selenium you need to induce WebDriverWait for the element_to_be_clickable() and you can use either of the following Locator Strategies: Using CSS_SELECTOR: select = Select(WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, “select.Select[name=”Format”]”)))) select.select_by_visible_text(“CSV”) Using XPATH: select = Select(WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, “//select[@class=”Select” and @name=”Format”]”)))) select.select_by_visible_text(“CSV”) Note : You have to … Read more

jQuery get selected option value (not the text, but the attribute ‘value’)

04/2020: Corrected old answer Use :selected pseudo selector on the selected options and then use the .val function to get the value of the option. $(‘select[name=selector] option’).filter(‘:selected’).val() Side note: Using filter is better then using :selected selector directly in the first query. If inside a change handler, you could use simply this.value to get the … Read more