html-select

HTML looping option values in drop down list

霸气de小男生 提交于 2019-12-03 22:42:00
I have been trying to do a form where a question about one's current age is included, and I have decided the easiest way to answer this question is by filling in a drop down list. So my first value in the drop down list shall be 1900 and then it shall increment by one till it reaches 2014. How do I do that? I wouldn't set a fixed final year, why recode again next year? Note that it is more effecient to update the DOM once than updaing the DOM for each year added to the list. HTML <select id="year"></select> Script var start = 1900; var end = new Date().getFullYear(); var options = ""; for(var

Getting selected options with querySelectorAll

馋奶兔 提交于 2019-12-03 22:18:33
I wonder if it's possible in Javascript to get the currently selected options in a <select multiple> field using the Selctors API rather than a "stupid" iteration over all options. select.querySelectorAll('option[selected="selected"]') only returns the options that were marked as preselected in the original HTML, which is not what I'm looking for. Any ideas? document.querySelectorAll('option:checked') Works even on IE9 ;) I was also experienced your issue, I have a feeling it's to do with JavaScript not recognising changes in the DOM. Here is a solution: jsFiddle document.getElementById('test'

value of select elements with “e.value” vs “e.options[e.selectedIndex].value”

北城以北 提交于 2019-12-03 21:04:09
问题 Given the HTML: <select id="mySelect"> <option value="1">test1</option> <option value="2">test2</option> <option value="3">test3</option> </select> and the javascript: var e = document.getElementById('mySelect'); To get the value of the select I can use e.value and e.options[e.selectedIndex].value . I am aware that e.options[e.selectedIndex].value will give me the selected value (1,2 or 3) and e.options[e.selectedIndex].text would give me test1, test2, test3 depending on which is selected. Is

Assign Attribute to @Html.DropdownList

怎甘沉沦 提交于 2019-12-03 20:15:45
问题 I want to assign some ID attribute name to my Dropdown list which is using data from the ViewBag as, ViewBag.Group = new SelectList(group, "GroupId", "Name"); and in the View side I have used Razor syntax for showing the Dropdown as, @Html.DropDownList("Group", "New", new { id="testID" } ) But I am getting the error on this line. Can I just assign ID of This Razor syntax? I know that the ID is generated with the Name "Playlist" But I am having 2 different dropdowns using same ViewBag. Because

mvc c# html.dropdownlist and viewbag

徘徊边缘 提交于 2019-12-03 17:50:12
问题 So I have the following (pseudo code): string selectedvalud = "C"; List<SelectListItem> list= new List<SelectListItem>(); foreach(var item in mymodelinstance.Codes){ list.Add(new SelectListItem { Text = item.Name, Value = item.Id.Tostring(), Selected = item.Id.ToString() == selectedvalue ? true : false }); } ViewBag.ListOfCodes = list; on my view: <%: Html.DropDownList("Codes", (List<SelectListItem>)ViewBag.ListOfCodes , new { style = "max-width: 600px;" })%> now, before it reaches the view,

html select list - get text value by passing in a variable?

孤街醉人 提交于 2019-12-03 17:00:59
I have a select list that displays a list languages. <select name="language_code" id="id_language_code"> <option value="ar">Arabic - العربية</option> <option value="bg">Bulgarian - Български</option> <option value="zh-CN">Chinese (Simplified) - 中文 (简体)‎</option> <option value="en" selected="selected">English (US)</option> <option value="fr-CA">French (Canada) - français (Canada)‎</option> </select> I am able to get the text value of the selected value using the following code [returns English (US) from the above select list]: $('#id_language_code option:selected').text() How can I get the text

input field disabled until radio button is checked (HTML)

痴心易碎 提交于 2019-12-03 16:42:29
问题 I have two fields, one of them is a text input field and the other is a select tag. The thing is I want one of them to be enabled only and the user should choose which one is enabled by clicking on one of the radio buttons above. So if the user chooses the first radio button the input field will be enabled and if he choose the second one the select tag will be enabled. Here's my code: <input type="radio" name="type" value="customurl">wanna custom url? <input type="text" name="custom"

In Django form, custom SelectField and SelectMultipleField

喜欢而已 提交于 2019-12-03 16:11:37
I am using Django everyday now for three month and it is really great. Fast web application development. I have still one thing that I cannot do exactly how I want to. It is the SelectField and SelectMultiple Field. I want to be able to put some args to an option of a Select. I finally success with the optgroup : class EquipmentField(forms.ModelChoiceField): def __init__(self, queryset, **kwargs): super(forms.ModelChoiceField, self).__init__(**kwargs) self.queryset = queryset self.to_field_name=None group = None list = [] self.choices = [] for equipment in queryset: if not group: group =

Javascript selecbox.options to array?

廉价感情. 提交于 2019-12-03 15:14:36
问题 From what I understand a option elements that popuate select elements in HTML are an array. So basically what i want to do is return an array string that is separated by commas. Tried to do selecbox.options.join(','); , but got an error that its not supported; anyone have an idea why? 回答1: It is not an array. It is an object. It is "array-like" from http://api.jquery.com/jQuery.each/ which CAN iterate over either: Iterate over both objects and arrays. Arrays and array-like objects with a

Two HTML-select boxes linked to each other

别来无恙 提交于 2019-12-03 14:56:46
问题 Hellloooooo... I have two <select> inputs like this <select id="sel1"> <option value="a">a</option> <option value="b">b</option> </select> <select id="sel2"> //if 'a' is selected above, //<option>apple</option>, <option>airplane</option> //if 'b' is selected above, //<option>banana</option>, <option>book</option> </select> And I want to list different sets of options according to the selection in sel1 . I could get the selected value using onchange attribute like this: <select id="sel1"