SQL PHP HTML ASP JavaScript articles and free scripts to download If you are facing any problem in viewing this page, please tell us
 

Disabling the second drop down list box


Please read the first part of the drop down list box before adding this feature. You can test the basic code first before adding the disable feature for second drop down list box.

To enable or disable the dropdown box we will keep one function in JavaScript and inside it we will keep the command for enable or disable based on the value or presence of first drop down value. If the selection of first drop down is present then only we will enable it otherwise we will keep the second list in disable condition.

To make the second dropdown box disable when the first time the page loads we will use the page onload command.

Here is the main code in which is to be added in JavaScript part. The full JavaScript part is kept here.

<SCRIPT language=JavaScript>
<!--
function reload(form)
{
var val=form.cat.options[form.cat.options.selectedIndex].value;
self.location='dd.php?cat=' + val ;
}
function disableselect()
{
<?
if(isset($cat) and strlen($cat) > 0){
echo "document.f1.subcat.disabled = false;";}
else{echo "document.f1.subcat.disabled = true;";}
?>
}
//-->

</script>


We will collect the value of $cat before this JavaScript code as based on this value our command inside the JavaScript will change.

Demo of this script with disable option

You can download the full code with this disable feature in this zip file.
Further readings
Double drop down list on managing second list based on selection of first list
Enable second drop down list after selection of first list box
Double drop down list Frequently Asked Question
Manageing three drop down list
Double drop down list demo
Three drop down list demo
Adding options to a list box from database
Managing list box options from a period button
Retaining the form field values once the page reloads
Controlling second list box by using Ajax & PHP

Sections
PHP
JavaScript
ASP
HTML
SQL
Photoshop
Articles SEO
PHP Tutorials
PHP Monthly Planner
PHP Introduction
Loops & structure
Array
Date & Time
Functions
Form Handling
File Handling
Math Functions
String Functions
GD Functions
Comment Posting
Content Management
PHP & Ajax
Popular Tutorials
Drop down list
File Upload
Signup script
Member Login
Line Graph
PHP MySQL Paging
PHP Calendar
Subscribe
Submit your email address and receive article and product notifications. Your email is safe with us.