Combo box id in JavaScript
Can I find the id
of a combo box in JavaScript, not its value?
jsp file code
function ChangeColor(colors) {
var partcolor = (colors.options[colors.selectedIndex].value);
if (partcolor=="black"){
document.getElementById("colorRow").style.backgroundColor = 'black';
}
else if(partcolor=="brown") {
document.getElementById("colorRow").style.backgroundColor ='brown';
} else if(partcolor=="yellow") {
开发者_如何学Python document.getElementById("colorRow").style.backgroundColor ='yellow';
}
}
java file code
public String getColor(String colorName) {
mySB.append("<select onchange=\"ChangeColor(this);\" style=\"font-size:0.8em;\" id=\"").append(colorName).append("\" name=\"").append(colorName).append("\">")
.append("<option value=\"\"> </option>");
}
How can I print the id of combo box here?
You can iterate the entire list of controls in the form and get their id's. Based on your need, you can differentiate the control in quest using the type,name etc.
function DisplayFormControl()
{
var str = '';
var elementList = document.getElementById('FormId').elements;
for(var i = 0; i < elementList.length; i++)
{
alert(elementList[i].type);
alert(elementList[i].name);
alert(elementList[i].value);
}
}
精彩评论