<script type="text/javascript">
    
var xmlHttp;
    
function createXMLHttpRequest(url){
        
if(window.ActiveXObject){
            xmlHttp
=new ActiveXObject("Microsoft.XMLHTTP");
        }
else if(window.XMLHttpRequest){
            xmlHttp
=new XMLHttpRequest();
        }

        
if(xmlHttp){
            xmlHttp.open(
"GET",url,false);
            xmlHttp.onreadystatechange
=function(){setState()};
            xmlHttp.send(
null);
        }

    }

    
function setState(){
        
var selTexts=document.getElementById("selText");
        
if(xmlHttp.readyState==4){
            
if(xmlHttp.status==200){
            parseMessage();
            
//alert(xmlHttp.responseText);
            //selTexts.innerHTML=xmlHttp.responseText;
            }

        }

    }

    
function parseMessage()
        
{
            
var xmlDoc=xmlHttp.responseXML.documentElement;
            
var xSel=xmlDoc.getElementsByTagName('select');
            
var select_root=document.getElementById('selText');
            select_root.options.length
=0;
            
            
for(var i=0;i<xSel.length;i++)
            
{
                
var xValue=xSel[i].childNodes[0].firstChild.nodeValue;
                
var xText=xSel[i].childNodes[1].firstChild.nodeValue;
                
var option=new Option(xText,xValue);
                
try{
                    select_root.add(option);
                }
catch(e){
                }

            }
 
        }

    
function getAttrValue(){
        
var selvalue=document.forms.select1.options[document.forms.select1.selectedIndex].value;
        
var url="../../../ProdAttrValueType";
        
if(selvalue==0){
            document.getElementById('defaltId').disabled
="";
            document.getElementById('select2').disabled
="disabled";
        }
else if(selvalue==1){
            document.getElementById('defaltId').disabled
="disabled";
            document.getElementById('select2').disabled
="disabled";
        }
else if(selvalue==2){
            document.getElementById('defaltId').disabled
="";
            document.getElementById('select2').disabled
="";
            createXMLHttpRequest(url);
        }

        
    }

</script>
public class ProdAttrValueType extends HttpServlet {
    
public void doGet(HttpServletRequest request, HttpServletResponse response)
            
throws ServletException, IOException {
        response.setContentType(
"text/xml");
        String xml_start
="<selects>";
        String xml_end
="</selects>";
        ServletContext sc
=this.getServletContext();
        WebApplicationContext wc
=WebApplicationContextUtils.getWebApplicationContext(sc);
        PrintWriter out 
= response.getWriter();
        IProdOfferAttrDao tt
=(IProdOfferAttrDao)wc.getBean("prodAttrDao");
        StringBuffer sb
=new StringBuffer("");
        List list
=tt.getAttrValueType();
        
if(list!=null){
            Iterator it
=list.iterator();
            
while(it.hasNext()){
                ProdOfferAttrActionForm pf
=(ProdOfferAttrActionForm)it.next();
                
//System.out.println(pf.getAttr_Val_Type());"+pf.getAttr_Val_Type()+"
                sb.append("<select><value>111</value><text>"+pf.getAttr_Val_Type()+"</text></select>");
            }

        }

        System.out.print(sb.toString());
        
//out.print()
        out.write(xml_start+sb.toString()+xml_end);
        out.flush();
        out.close();
    }


王永庆 2007-12-20 17:23 发表评论
" /> ajax表单级联-----晕到死
首页 文章 Ajax ajax表单级联-----晕到死

邮件订阅

ajax表单级联-----晕到死 E-mail
用户评价: / 0
好 
作者:王永庆   
2007-12-19 23:46
<script type="text/javascript">
    
var xmlHttp;
    
function createXMLHttpRequest(url){
        
if(window.ActiveXObject){
            xmlHttp
=new ActiveXObject("Microsoft.XMLHTTP");
        }
else if(window.XMLHttpRequest){
            xmlHttp
=new XMLHttpRequest();
        }

        
if(xmlHttp){
            xmlHttp.open(
"GET",url,false);
            xmlHttp.onreadystatechange
=function(){setState()};
            xmlHttp.send(
null);
        }

    }

    
function setState(){
        
var selTexts=document.getElementById("selText");
        
if(xmlHttp.readyState==4){
            
if(xmlHttp.status==200){
            parseMessage();
            
//alert(xmlHttp.responseText);
            //selTexts.innerHTML=xmlHttp.responseText;
            }

        }

    }

    
function parseMessage()
        
{
            
var xmlDoc=xmlHttp.responseXML.documentElement;
            
var xSel=xmlDoc.getElementsByTagName('select');
            
var select_root=document.getElementById('selText');
            select_root.options.length
=0;
            
            
for(var i=0;i<xSel.length;i++)
            
{
                
var xValue=xSel[i].childNodes[0].firstChild.nodeValue;
                
var xText=xSel[i].childNodes[1].firstChild.nodeValue;
                
var option=new Option(xText,xValue);
                
try{
                    select_root.add(option);
                }
catch(e){
                }

            }
 
        }

    
function getAttrValue(){
        
var selvalue=document.forms.select1.options[document.forms.select1.selectedIndex].value;
        
var url="../../../ProdAttrValueType";
        
if(selvalue==0){
            document.getElementById('defaltId').disabled
="";
            document.getElementById('select2').disabled
="disabled";
        }
else if(selvalue==1){
            document.getElementById('defaltId').disabled
="disabled";
            document.getElementById('select2').disabled
="disabled";
        }
else if(selvalue==2){
            document.getElementById('defaltId').disabled
="";
            document.getElementById('select2').disabled
="";
            createXMLHttpRequest(url);
        }

        
    }

</script>

public class ProdAttrValueType extends HttpServlet {
    
public void doGet(HttpServletRequest request, HttpServletResponse response)
            
throws ServletException, IOException {
        response.setContentType(
"text/xml");
        String xml_start
="<selects>";
        String xml_end
="</selects>";
        ServletContext sc
=this.getServletContext();
        WebApplicationContext wc
=WebApplicationContextUtils.getWebApplicationContext(sc);
        PrintWriter out 
= response.getWriter();
        IProdOfferAttrDao tt
=(IProdOfferAttrDao)wc.getBean("prodAttrDao");
        StringBuffer sb
=new StringBuffer("");
        List list
=tt.getAttrValueType();
        
if(list!=null){
            Iterator it
=list.iterator();
            
while(it.hasNext()){
                ProdOfferAttrActionForm pf
=(ProdOfferAttrActionForm)it.next();
                
//System.out.println(pf.getAttr_Val_Type());"+pf.getAttr_Val_Type()+"
                sb.append("<select><value>111</value><text>"+pf.getAttr_Val_Type()+"</text></select>");
            }

        }

        System.out.print(sb.toString());
        
//out.print()
        out.write(xml_start+sb.toString()+xml_end);
        out.flush();
        out.close();
    }
最后更新于: 2007-12-19 23:46
 

欢迎转载

本站文章欢迎转载,但请注明出处(http://www.javajia.com,Java家)