4

I'm using the jQuery MultiSelect Widget. When using IE, if I select 3 options from the basic dropdown, browse to another page and then press the browser back button, the values are retained in the dropdown. If I refresh the page, the values are still retained. A force refresh clears the values.

In Chrome if I do the same thing the values are not retained.

With my website (which is unfortunately not yet accessible via the Internet), in IE8, the checked state of the checkboxes seems to be retained visually but the state of the checkbox is unchecked.

I have tried calling the 'uncheckAll' method and the checkboxes are still checked. I put an alert in my code to display the number of selected options and the value is zero even though checkboxes are selected.

How is the state of the multiselect list being retained by IE and can it be prevented?

Anthony
  • 1,706
  • 2
  • 22
  • 46
  • Did you disabled caching in the site with multi-select widget like shown here: http://stackoverflow.com/questions/1341089/using-meta-tags-to-turn-off-caching-in-all-browsers? – lzdt Jun 06 '13 at 08:52

2 Answers2

0

Calling unchekAll() method of multiselect plugin seems to be the easiest way. As i cannot see your code, maybe you are not calling it the right way:

$("select").multiselect("uncheckAll");

But now, where to call this method?

For cross browser consistency, i think the right way is to use the onbeforeunload handler, which is fired in all browsers as i'm aware of. So, this snippet should work in all case:

window.onbeforeunload = function(){$("select").multiselect("uncheckAll")};

Let me know if this fix your issue?

A. Wolff
  • 74,033
  • 9
  • 94
  • 155
  • This fixed the issue but I still don't know why IE is the only browser to retain the values. – Anthony Jun 02 '13 at 22:57
  • If you use this link (not nested in iframe): http://www.erichynds.com/examples/jquery-ui-multiselect-widget/demos/basic.htm You can see than not only IE retains data. I suspect you are embeding it in an iframe as the demo page of the widget is doing it. Looks like to me more an iframe relative inconsistency between browsers than a plugin relative behaviour. Would need more tests to be sure – A. Wolff Jun 02 '13 at 23:10
  • I just used the link in IE8 and Chrome, selected 4 values from the basic list and then pressed refresh. IE8 retained '4 selected' and Chrome reverted to 'Select options'. I'm not using it in an iframe. – Anthony Jun 03 '13 at 00:44
  • Ya using refresh, inconsistency persists but not if navigate to other page then use back button. Firefox and Safari keeps datas too on refresh. So in this case, only Chrome reset datas on refresh. – A. Wolff Jun 03 '13 at 08:30
0

Try unbinding before binding the widget. It is a good practice to unbind the event attachments before attaching to avoid any problems like above.

Try

$("select").unbind(); 

And then attach the multiselect. jquery-unbind() off() all does the same use the one appropriate to your jquery version. I think you will get the same problem in mozilla too.

Aneesh Mohan
  • 1,077
  • 8
  • 17