﻿function updateStainDropDown(form)
    {
       var val=form.ddStainCategory.options[form.ddStainCategory.options.selectedIndex].value;
       //alert (val);   
       //createRequest();
       var url = "AjaxGetStains.aspx?id=" + val;
       request.open("GET",url,true);
       request.onreadystatechange = updateDropDown;
       request.send(null);
    }
    
    function updateDropDown()
    {
    
        if(request.readyState == 4)
        {
            /*Get the response*/
            var stain = (request.responseText); 
            var stain_array = new Array();
            stain_array = stain.split(",");
            
            /*Update the drop down with the response*/
            
            var dropdown = document.getElementById("ddStainType");
            
            /*clear the current dropdown*/
            for (var i = (dropdown.options.length-1); i >= 0; i--){
                 dropdown.options[i]=null;
                }
            /*re-populate using array*/
            var split = new Array();
            var value;
            var text;
            
            for (var i=0; i < stain_array.length;++i){
                
                split=stain_array[i].split("~");
                value=split[0];
                text=split[1];                
                addOption(dropdown,text,value);
                }
        }
    }
    
    function addOption(selectbox,text,value )
    {
        var optn = document.createElement("OPTION");
        optn.text = text;
        optn.value = value;
        selectbox.options.add(optn);
    }
