Disable dropdown list using Javascript

Last updated on June 15th, 2016 at 09:45 am

Click to rate this tutorial!
[Total: 5 Average: 4]

Disable dropdown list using Javascript

This tutorial will explain how to Disable dropdown list inside a form using javascript. If you have lets say a dropdown list of two values then you can disable that using javascript when you mark a checkbox.

Disable Dropdown List Using Javascript
Disable Dropdown List Using Javascript

Here as an example I have a form named “frm” and the selection named “sel”. I can use Javascript to disable it by calling document.frm.sel.disabled. Try to save the code below to an HTML page and run it to check how it works.

<form name="frm">
<select name="sel">
<option value="1">one</option>
<option value="2">two</option>
</select>
<input type="checkbox" onclick="disable(this.checked)" /> Disable
</form>
<script language="JavaScript">
<!--
function disable(disableIt)
{
	document.frm.sel.disabled = disableIt;
}
//-->
</script>

(NOTE:- Page updated on 15th Jun 2016. Originally posted on 16th September 2010)

Click to rate this tutorial!
[Total: 5 Average: 4]

Leave a Reply

Your email address will not be published.