开发者

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=\"\">&nbsp;</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);

} 

}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜