简体   繁体   中英

Select box persists with value

I am having a JSP page which includes another JSP which has all the common customized popup boxes. On my main JSP page I have a button that says "Cancel". when I press this the Javascript is invoking a div which is present in the JSP file which I have included.

The invoked pop up has a div and in it there is a dropdown box. The user can select the reason from the dropdown box. Now if the user closes the pop-up box and clicks the Cancel button again, the dropdown box persists the value that was selected earlier.

I want to make the value to go to default. If I refresh the page the value is removed. I tried to refresh the page but then it gives an alert to confirm the submission, which doesn't look good in the terms of user experience. I am using Struts 2.

How can I do this?

I found the solution for the problem. Posting here for others. My html code

<select name="cancel.cancelReasonCode" 
        id="selectCancellationReason" 
        data-theme="c" 
        data-mini="true" 
        data-native-menu="false" 
        tabindex="-1">
    <option value="0">Select Cancellation Reason</option>
    <option value="3">Created by mistake</option>
    <option value="2">Incorrect Id</option>
    <option value="1">Data not available</option>
</select>

Javascript code

var myselect = $("select#selectCancellationReason");
myselect[0].selectedIndex = 0;
myselect.selectmenu("refresh");

I am using jquery and jquery mobile in my application.

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