How to get index from html:select component?

1000 views Asked by At
Page code:
---------

 <html:select property="projectId" styleClass="ctrlwidthfirstpair">
    <html:options  collection="projects" property="value" labelProperty="label" />
 </html:select>

JavaScript:

function isProjectSelected() {
    var selIndex = document.getElementById("projectId").selectedIndex;
    if (selIndex == 0) {
        alert("Please Select Project");
        return false;
    }
    return true;  
}

document.getElementById("projectId") returns null value.

How to get index of selected option of <html:select> component?

2

There are 2 answers

2
Phil On BEST ANSWER

The attribute you're looking for is styleId. Next time, try reading the fine manual.

<html:select styleId="projectId" ...
0
Wundwin Born On

All html tags in Struts styleId property will be rendered as id attribute. Try like that..

<html:select property="projectId" styleId="projectId" styleClass="ctrlwidthfirstpair">
<html:options  collection="projects" property="value" labelProperty="label" />