开发者

unabled to keep selected value in a combo box

Sir,

Im trying to implement the search feature in my website.

when i select a value into the combobox, the form will be Posted and the result will be shown on the same page.But after the response comes from the servlet, the default value is displayed into the combobox. i want is to keep the开发者_开发百科 selected category of the combo by default in the form after posted

For eg.,the combobox default value is'C001'and If i select the 'C008' in the combo and click search, after form submit, the combo should show 'C008' as default selected option. Please help me. Any help will be appreciated


You should use AJAX. This way the page will be not reloaded and value in combo box will not change.


in js:

function callThisOnchangeOfComboBox(){

        var xmlhttp;
        if (window.XMLHttpRequest) {
            xmlhttp = new XMLHttpRequest();
        } else {
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        }

        xmlhttp.open("POST", urlOfServlet, false);
        xmlhttp.send(null);
        //----------- parse xmlhttp.responseText as you need. 
}


You'll have to pass the "selected" tag to the correct option as follow:

<option value="" selected>

You could check the value within your while loop and put the "selected" string when appropiate.


 <option value='<%=courseId%>' selected="selected"><%=courseId%></option>
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜