Asked  6 Months ago    Answers:  5   Viewed   23 times

According to HTML specs, the select tag in HTML doesn't have a readonly attribute, only a disabled attribute. So if you want to keep the user from changing the dropdown, you have to use disabled.

The only problem is that disabled HTML form inputs don't get included in the POST / GET data.

What's the best way to emulate the readonly attribute for a select tag, and still get the POST data?



You should keep the select element disabled but also add another hidden input with the same name and value.

If you reenable your SELECT, you should copy its value to the hidden input in an onchange event and disable (or remove) the hidden input.

Here is a demo:

$('#mainform').submit(function() {
    return false;

$('#enableselect').click(function() {
    $('#mainform input[name=animal]')
        .attr("disabled", true);
        .attr('disabled', false)
    	.attr('name', 'animal');
    return false;
#formdata_container {
    padding: 10px;
<script src=""></script>
    <form id="mainform">
        <select id="animal-select" disabled="true">
            <option value="cat" selected>Cat</option>
            <option value="dog">Dog</option>
            <option value="hamster">Hamster</option>
        <input type="hidden" name="animal" value="cat"/>
        <button id="enableselect">Enable</button>
        <select name="color">
            <option value="blue" selected>Blue</option>
            <option value="green">Green</option>
            <option value="red">Red</option>

        <input type="submit"/>

<div id="formdata_container" style="display:none">
    <div>Submitted data:</div>
    <div id="formdata">
Tuesday, June 1, 2021
answered 6 Months ago

Works for me. Just tried

<select name="multiselect[]" ...

Results in a URL ?multiselect%5B%5D=2&multiselect%5B%5D=3

which will make $_GET['multiselect'] an array in PHP.

Perhaps you have something else in your system, stripping the [] ?

Saturday, May 29, 2021
answered 7 Months ago

I had same requirement as yours and I figured out an easy way to do this. If you want a "readonly" field to be "required" also (which is not supported by basic HTML), and you feel too lazy to add custom validation, then just make the field read only using jQuery this way:


form the suggestions in comments

<input type="text" class="readonly" autocomplete="off" required />

    $(".readonly").on('keydown paste focus mousedown', function(e){
        if(e.keyCode != 9) // ignore tab

Credits: @Ed Bayiates, @Anton Shchyrov, @appel, @Edhrendal, @Peter Lenjo


<input type="text" class="readonly" required />

Sunday, August 1, 2021
answered 4 Months ago

You didn't say anything about file types so I used HTML-5 formats that work in Safari.

    <meta charset="UTF-8">
    <title> audio video</title>

    <audio id="audioInHTML" controls="controls">     
    <source src="audio.wav" type="audio/wav"/>

    <video id="videoInHTML" width="320" height="240" controls="controls">
      <source src="movie.mp4" type="video/mp4" />

    <div id="playButtonDiv" </div>

    <input type="button" value="PlaySoundAndVideo" onClick="PlaySoundAndVideo('videoInHTML'),PlaySoundAndVideo('audioInHTML')">



    function PlaySoundAndVideo(soundObj,videoObj) {
    var soundAndVideo=document.getElementById(soundObj,videoObj);;


    <style type="text/css">

    #playButtonDiv {


Sunday, August 15, 2021
answered 4 Months ago

What you should do is implement your own controls (or use an existing set such as videojs)
You can read my answer to this question: Html5 video overlay architecture

Wednesday, November 10, 2021
answered 3 Weeks ago
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :