Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <select id="countries" onfocus="this.defaultIndex=this.selectedIndex;" onchange="this.selectedIndex=this.defaultIndex;">
- <option value="1">Country1</option>
- <option value="2">Country2</option>
- <option value="3">Country3</option>
- <option value="4">Country4</option>
- <option value="5">Country5</option>
- <option value="6">Country6</option>
- <option value="7" selected="selected">Country7</option>
- <option value="8">Country8</option>
- <option value="9">Country9</option>
- </select>
- var readonlySelect = function(selector, makeReadonly) {
- $(selector).filter("select").each(function(i){
- var select = $(this);
- //remove any existing readonly handler
- if(this.readonlyFn) select.unbind("change", this.readonlyFn);
- if(this.readonlyIndex) this.readonlyIndex = null;
- if(makeReadonly) {
- this.readonlyIndex = this.selectedIndex;
- this.readonlyFn = function(){
- this.selectedIndex = this.readonlyIndex;
- };
- select.bind("change", this.readonlyFn);
- }
- });
- };
- $("select.myselect").bind("focus", function(){
- if($(this).hasClass('readonly'))
- {
- $(this).blur();
- return;
- }
- });
- $('select[name=country]').attr("disabled", "disabled");
Add Comment
Please, Sign In to add comment