How to ensure a form field is submitted when it is disabled?

I have a select form field that I want to mark as “readonly”, as in the user cannot modify the value, but the value is still submitted with the form. Using the disabled attribute prevents the user from changing the value, but does not submit the value with the form. The readonly attribute is only … Read more

How do I clear all options in a dropdown box?

My code works in IE but breaks in Safari, Firefox, and Opera. (big surprise) document.getElementById(“DropList”).options.length=0; After searching, I’ve learned that it’s the length=0 that it doesn’t like. I’ve tried …options=null and var clear=0; …length=clear with the same result. I am doing this to multiple objects at a time, so I am looking for some lightweight … Read more

How do I programatically select an HTML option using JavaScript?

I have option menu like this: <form name=”AddAndEdit”> <select name=”list” id=”personlist”> <option value=”11″>Person1</option> <option value=”27″>Person2</option> <option value=”17″>Person3</option> <option value=”10″>Person4</option> <option value=”7″>Person5</option> <option value=”32″>Person6</option> <option value=”18″>Person7</option> <option value=”29″>Person8</option> <option value=”28″>Person9</option> <option value=”34″>Person10</option> <option value=”12″>Person11</option> <option value=”19″>Person12</option> </select> </form> And now I want to change the selected option by using an href. For example: <a href=”https://stackoverflow.com/questions/10911526/javascript:void(0);” onclick=”document.getElementById(‘personlist’).getElementsByTagName(‘option’)[11].selected … Read more

Is there an onSelect event or equivalent for HTML ?

I have an input form that lets me select from multiple options, and do something when the user changes the selection. Eg, <select onChange=”javascript:doSomething();”> <option>A</option> <option>B</option> <option>C</option> </select> Now, doSomething() only gets triggered when the selection changes. I want to trigger doSomething() when the user selects any option, possibly the same one again. I have … Read more

Removing an item from a select box

How do I remove items from, or add items to, a select box? I’m running jQuery, should that make the task easier. Below is an example select box. <select name=”selectBox” id=”selectBox”> <option value=”option1″>option1</option> <option value=”option2″>option2</option> <option value=”option3″>option3</option> <option value=”option4″>option4</option> </select> 15 Answers 15

How to select a drop-down menu value with Selenium using Python?

I need to select an element from a drop-down menu. For example: <select id=”fruits01″ class=”select” name=”fruits”> <option value=”0″>Choose your fruits:</option> <option value=”1″>Banana</option> <option value=”2″>Mango</option> </select> 1) First I have to click on it. I do this: inputElementFruits = driver.find_element_by_xpath(“//select[id=’fruits’]”).click() 2) After that I have to select the good element, lets say Mango. I tried to … Read more

How to have a default option in Angular.js select box

I have searched Google and can’t find anything on this. I have this code. <select ng-model=”somethingHere” ng-options=”option.value as option.name for option in options” ></select> With some data like this options = [{ name: ‘Something Cool’, value: ‘something-cool-value’ }, { name: ‘Something Else’, value: ‘something-else-value’ }]; And the output is something like this. <select ng-model=”somethingHere” ng-options=”option.value … Read more