based on 1st dropdown, 2nd dropdown value populated from database

puneet kumar
puneet kumar used Ask the Experts™
on
One drop-down has 2 static value 0 or 1. Based on this selection  2nd drop-down value come from database .

In first drop-down if value is 0 Then Second drop-down static value "ALL"  comes, if first drop-down value is 1 then second drop-down values come from database.

Does anyone have an example of how I can accomplish something like this in JavaScript?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Multitechnician
Top Expert 2014
Commented:
test page : https://jsfiddle.net/akpmse73/

jQuery(function($) {
   $("#<%= zeroneID.ClientID %>").on("change", function () {
        var v = $(this).val();
        if(v==0) {
            $("#<%= fromdatabaseID.ClientID").prop("disabled", true).hide();
            $("<input id='fromdatabaseINPUT' name='fromdatabase' value='ALL' readonly='readonly' >").insertAfter("#<%= fromdatabaseID.ClientID");
        } else { // v == 1...should....
            $("#fromdatabaseINPUT").remove();
            $("#<%= fromdatabaseID.ClientID").prop("disabled", false).show();
        }
   }).change();
});

Open in new window


<select name="zerone" id="zeroneID">
    <option value="0">ZERO</option>
    <option value="1">ONE</option>
</select>
<br>
<select name="fromdatabase" id="fromdatabaseID">
    <option value="4">4</option>
    <option value="5">5</option>
    <option value="6">6</option>
    <option value="7">7</option>
    <option value="8">8</option>
    <option value="9">9</option>
</select>

Open in new window

Author

Commented:
Thanx

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial