-1

I want to readonly select box. But I post value from that element. When I disabled it then select box can't post value.

<select name="office_name" id="office_name" readonly>
    <option value="">----Select Office----</option> 
    <option value="1">Bengli</option>   
    <option value="2">English</option>  
</select>   

Readonly does not work but disabled work. But I need readonly not disabled. Is it Possible?

Praveen Kumar Purushothaman
  • 164,888
  • 24
  • 203
  • 252
Salman Quader
  • 195
  • 2
  • 13

2 Answers2

1

What about avoiding any mousedwon/keydown event:

$('#office_name').on('mousedown keydown', function(){ 
  return !$(this).hasClass('readonly');
});

And then, just toggle readonly class to able or disable user selection.

See -jsFiddle-

A. Wolff
  • 74,033
  • 9
  • 94
  • 155
0

You can do like:

Just don't disable option which you want to post else disable all options

So 2 value will be posted into PHP now.

<select>
  <option disabled="disabled">1</option>
  <option selected="selected">2</option> <!-- just dont disable option which you want to post else disable all options-->
  <option disabled="disabled">3</option>
</select>
Praveen Kumar Purushothaman
  • 164,888
  • 24
  • 203
  • 252
Dhara Parmar
  • 8,021
  • 1
  • 16
  • 27