Submitting Disabled Option Value in A Form

Posted By : Himanshu Agarwal | 31-Jan-2018
Disabled values are not submitted on form submit in a select box.
 
Disabled attributes properties:
Disabled controls do not receive focus.
Disabled controls are skipped in tabbing navigation.
Disabled controls cannot be successfully posted.
 
There are two ways to submit the disabled value:
1) We disable a value so that user cannot change it, so we can delete 
all other values of the dropdown keeping the required value.
 
2) Using a hdden field:
The code for which is here
 
<script type="text/javascript">

function getOption() {
    var hiddenCarId = document.getElementById("hCar");
    var carId = document.getElementById("carId");
    hiddenCarId.value = carId.value;

    document.theform.submit();
}

</script>

<bodyt>

<form method="POST" action="" name="theform">
    
    

    
    
</form>
</body>

About Author

Author Image
Himanshu Agarwal

He works on Frontend Technologies like Javascript, Angular, HTML, CSS, jQuery.

Request for Proposal

Name is required

Comment is required

Sending message..