简体   繁体   中英

obtain listValue of selected item in <s:select> in struts2

I have a JSP page which uses an <s:select> tag.

<s:select 
        id="userGroups"
        headerKey="-1"
        headerValue="------ Select Group ------" list="userGroupList"
        listValue="groupName"
        onchange="selectGroup()">   

what i want to achieve is to display the listValue of the selected item using a javascript function. what may be the way to do this?

EDIT: my selectGroup() function:

function selectGroup(){
    var selectedGroup = document.getElementById('userGroups');
    alert(selectedGroup.value);
}
function selectGroup(){
    var sel = document.getElementById('userGroups');
    alert(sel.options[sel.selectedIndex].text);
}

or

<s:select 
    id="userGroups"
    headerKey="-1"
    headerValue="------ Select Group ------" list="userGroupList"
    listValue="groupName"
    onchange="selectGroup(this)"> 

function selectGroup(sel){
    alert(sel.options[sel.selectedIndex].text);
}

or

<s:select 
    id="userGroups"
    headerKey="-1"
    headerValue="------ Select Group ------" list="userGroupList"
    listValue="groupName"
    onchange="alert(this.options[this.selectedIndex].text);"> 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM