Tuesday, August 31, 2010

Javascript change dropdown or select option value which is index

I google for "javascript change select value" and turn out not really help full
The keyword for select is more like dropdown
while the value is index
So it must be "javascriptchange dropdown index"

The purpsoe of this post is a javascript is to change the selection inside the dropdown into something you want.



Just like the dropdown above. The default value is seet to the first option which is "Hello"
When I click a certain script with value "World", the script will change the dropdown into to "World". This is what I want. Below is the code


function changeDropDown( dropdownidname, dropdownvalue)
{
var testingga = window.opener.document.EditView.elements[dropdownidname];
//In most case it will be document.getElementById(dropdownidname); I think

for (var i=0; i < testingga.length; i++)
{
if (testingga[i].value == dropdownvalue)
{
testingga[i].selected = true;
}
}
}

No comments: