I have one select, I can say wich element is selected:
<select name="myselect">
<option value="100">A</option>
<option value="101">B</option>
<option value="102">C</option>
</select>
this line will select the option B
myselect.options.selectedIndex = 1;
but, how can I do if I want to select the option B without knowing it´s position?
I mean, I want to select the option B and the value 101, but I don´t know it´s position
I am trying to figure out if there is a way to get the selectedIndex of a select by its value, without going through a loop to check for it.
I know the value of a select, and I want to make the option be selected. But I don't know the selectedIndex. Was hoping to do it without going through a loop to determine the selectedIndex
I am using IE5 and have a select-box with options that have different colors. Is there a way to read out the style attribute of the selectedIndex (here: color)? See simple demo script here under...
Instead of using alert, I've tried simply assigning sBox.options.length to throwaway variable, but I end up with the same results as the first snippet.
why does this work under FF and only ONCE in IE but the problem remains the same as the firefox only code crashed IE's javascript.so it works only once still.SOLUTION -> changed event from onchange to onclick for my checkbox calling that function !
I'm using selectedIndex to change an option in a listbox, but I'm finding that the onChange event doesn't fire unless I manually make a selection. Is there any way to effect the change by JS so that the event works?
This is my sample code so far. Currently it only works for "Akali" under the "Select a champion..." dropdown list.
The way it works is, you select a level from 1-10 from the "Select a level..." dropdown list, and then you select Akali from the other dropdown list and her "Health" is calculated by "lvl * 80 + 510" which works perfectly. But the problem is if you change the level that value does not update automaticly. Instead the person using it has change the level to the new level they desire, change the champion and change it back again for it to update. Which normally would be ok, but I will be adding much, much more data to the page and I can't ask people to have to update stuff 10 times just to get accurate figures.
I took this from the w3schools jQuery tutorial and built a button, so ignore the way it currently works. I guessed that with a button it would when pressed it would take the latest, aka current selectedIndex values and all would work fine, and it does actually. But I just wanted to ask if there was any way to keep all the information updated at all times without a button, or maybe a button that will update everything on the website with just one click?
for (var i = 0; i < optionArray.length; i++) { myNewGrandChildElement = window.document.createElement(''option''); myNewGrandChildElement.setAttribute(''value'', optionArray[i]["value"]); if (optionArray[i]["selected"]!=null) {
If the user types "a" then the select box is populated with "Choose An Animal...", then the three three animals beginning with A. So far so good. But if the user selects say Albatross and then types the letter b then the option "Bear" is selected rather than "Choose An Animal". Although the code is sel.selectedIndex = 0; (not 1). How can I force the selected index to 0 when a choice has been made previously? Is this a bug - if so it is the same in IE and FF.
I want to add more dropdown options which are dependent on previous options. Now I have "hand" and "loft". I want to add next option "model" How to add third dropdown option box?
Is it possible to trigger a change event on a select field when the selectedIndex or val is set with jQuery? I've tried it and it doesn't seem to work. I'm attempting to replace a select field with one of my own design. The issue is if i attached a change event to a select field, when the index is changed it needs to fire that event. Basically if a select field is replaced with my list and a seperate script is set on the select list, I need that seperate script to fire without knowing what it is.
i currently have a few problems with my code, but currently i want to get my options into my function
<select id="menu"> <option value="first">First Time User</option> <option value="Frequent">Frequent Flier</option> <option value="Buying">Buying a Degree</option> </select>
How do I use this info to make it part of my function, for example when First Time user is selected and the function is executed it i want a windows.alert to come up but i don't know how to code that.
I have a bit of a question about CGI...I'm not very knowledgeable about it, so I have a specific question. Can you set up a site in which sites can be rated using CGI?
I've tried to access the value of a selected option through the following getSelectValue function, passing the name of the select
function getSelectValue (name) { var sel = document.getElementsByName(name)[0]; var i = sel.options.selectedIndex; return i == -1? "": sel.options[i].value; }
That dosn't work. I'm just using the title attribute as a place to hold the information I need. Maybe there is another attribute that would work better for this? How can I get the contents of the attribute?
<script> alert("You are not allowed to see this page"); self.location="javascript:history.go(-1)"; </script> The above script has one option. I like to make two options(yes or no) like the following.
Code: <script> alert("Are you sure to delete?"); Yes(self.location="delete.php"); No(self.location="javascript:history.go(-1))"; </script>
I have a drop down with alot of options say about 6000 cities and districts. I need to select all options if user selects "All checkbox". I use "on change" and a for loop to do this, but it takes a lot of time to select all these options. Is there any faster way to select all these options?
function selectAll() { var element = document.getElementById("location"); var length = document.getElementById("location").length;
I have two drop down box's in a form, how would I go about changing the options of the seccond one depending on what option is selected in the first one?
For example, if there's a drop down box with "a", "b" and "c" as the options, and another drop down box with "1", "2" and "3" as the options; then when you select "a" on the first drop down box the values of the seccond one changes to "a1", "a2" and "a3". This should work for all the options of the first drop down box.
In JS, how can I change the selected value of a dropdownlist(select options) I know the value of indexed value of the selected value before it is changed.
I got this simmple function, It stays on onChange on select and on change it hides all objects with ID equal to select name plus the optionvalue. It works perfectly in Opera and FF, but IE crashes because says that options object is null
the problem is in for (optionId in what.options) It seems that IE does NOT return the list of options, but only some other objects: language scrollheight, istextedit, currentstyle, document, and onmouseup
Please can you help me how can I go throuth that cycle? I need to get the values of all options in select. Thank you
function showHide (what) { selectedId=what.options.selectedIndex; selectedValue=what.options[selectedId].value; selectedObject = document.getElementById(what.name+selectedValue); selectedObject.className=""; for (optionId in what.options) { optionValue=what.options[optionId].value; if (optionValue) { optionObject = document.getElementById(what.name+optionValue); if (optionId!=selectedId) { optionObject.className="hidden"; } } } }
The user must bem select options in this 4 files in order, for example, he must bem select first "First Choice" next "Second Choice"... The options not be same.