java – Using Scriptlet in JavaScript

javajavascriptjspjstlscriptlet

i have a jsp page… i am adding some content to page dynamically depending upon request parameters (an array will be returned by request) based on this i have to create a drop down. i want to do this on change of another drop down.. so can be done using javascript only but i am unable to use scriptlet in js, is this really possible??

EDIT : i wanna perform some actions on the values retrieved from scriptlet as well

it will be of this sort

function changeMethod(){
    var templateselected = document.getElementById("templateDropDown");
    var versionDropDown = document.getElementById("versionDropDown");
    if ( templateselected.options.selectedIndex != -1)
    {
        var selected=templateselected[templateselected.options.selectedIndex].value;
        removeChildNodes(versionDropDown);
        <% 
        RetrieveTempSecVersions[] lsListOfFiles = (RetrieveTempSecVersions []) request.getAttribute("templateNames") ;
        for (int i=0 ; i < lsListOfFiles[1].getVersionNumber().length ; i++ ) {
            System.out.println("helllooooo");%>
        versionDropDown.innerHTML+='<OPTION VALUE="'+<%=lsListOfFiles[1].getVersionNumber()[i]%>+'">'+<%=lsListOfFiles[1].getVersionNumber()[i]%>+'</OPTION>';
        <%}%>
    }
}

Best Answer

Yes you can have something like this

function addCombo() {
    var textb = document.getElementById("txtCombo");
    var combo = document.getElementById("combo");

    var option = document.createElement("option");
    <c:forEach var="state" items="${stateList}" varStatus="status">  
    option.text = "${state}";
    option.value = "${state}";
    try {
        combo.add(option, null); //Standard
    }catch(error) {
        combo.add(option); // IE only
    }
    </c:forEach>
    textb.value = "";
} 

Note: I haven't tested this code , this is just a demonstration

Related Question