如何使用ajax比较两个动态创建的下拉列表 [英] how to compare two dynamically created dropdowns using ajax

查看:56
本文介绍了如何使用ajax比较两个动态创建的下拉列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道我的问题的逻辑,请帮助我,我有一些下拉菜单,如drop down1和drop down2,它们是动态创建的,如果drop down1有1,2,3等列表项,我需要提供警报4和下拉列表2由列表项组成,如a,b,c,d,如果最终用户选择一个项目,则不应使用相同的项目,如果最终用户在dropdown1中选择项目1,在dropdown2中选择a如果最终用户尝试选择相同的组合,那么不应该使用该组合,然后我需要在这里提供一个警告我在javascript中使用ajax尝试下拉值时选择了一些逻辑

DDLID .Attributes.Add(onChange,return fncheckType(count,sourceid,Dropdownid,points));

这里i是count,Dropdownid是dropdown1 id和points值为No我需要用于循环的源代码我只是感到困惑所以请在预付款中帮助我很多感谢

I want to know the logic for my problem please helps me I have some dropdowns like drop down1 and drop down2 which are created dynamically and where I need to provide an alert if drop down1 has list items like 1,2,3,4 and dropdown 2 consist of list item like a,b,c,d if end user select one item then the same item should n’t be used, here if end user select item"1" in dropdown1 and "a" in dropdown2 then the combination should not be used if end user try to select the same combination then I need to provide an alert here there is some logic I tried in javascript using ajax when drop down value is selected then
DDLID.Attributes.Add("onChange", "return fncheckType (count,sourceid,Dropdownid,points)");
Here "i" is count and Dropdownid is dropdown1 id and "points" value of No.of source where I need to used for loop I just got confused so please help me thanks a lot in advances

function fncheckType(i,SourceId,Ddlid,noofpntsid)
  {
      if(i!='''')
      {

          var xmlhttp;
          var noofpoints=noofpntsid;
          var PointPfxList='''';
          var SelectedType='''';

          try
          {
             var Typeddlid=document.getElementById(Ddlid);
               var SelectedType=Typeddlid.options[Typeddlid.selectedIndex].value

              if ((document.getElementById ("SourceIdTxt").value==SourceId)&&(document.getElementById ("SourceIdTxt").value!='''')){
               for(k=1;k<=noofpntsid;k++)
              {

               var Typeddlid1= document.getElementById("Typ" + k + i);
               var SelectedType1=Typeddlid1.options[Typeddlid1.selectedIndex].value

             if((SelectedType) != SelectedType1)
             {
                      if(PointPfxList=='''')
                          {
                           var PointPfxList=SelectedType1   //Typeddl.options[Typeddl.selectedIndex].value

                          }
                      else
                          {
                              var PointPfxList=PointPfxList +'',''+SelectedType1// Typeddl.options[Typeddl.selectedIndex].value
                          }
               }//if
           }//for

           }//first if

       else
       {
       document.getElementById ("SourceIdTxt").value=SourceId;
       }
       }//try

           catch(ex)
           {

           }



          try
          {
          xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
          }
          catch(ex)
          {
             try {
                   xmlhttp=new ActiveXObject("MSxml2.XMLHTTP");
                 }
             catch(ex)
               {
                  try
                  {
                    xmlhttp=new XmlHttpRequest();
                  }

                   catch(ex)
                  {
                    alert("please update the webbrowser");
                  }
               }

          }

          xmlhttp. önreadystatechange=function()
          {

              if(xmlhttp.readystate==4)
              {
              var s="abc"
              s=xmlhttp.responseText

                  if(s==2)  // Sampling Point Prefix already exists
                  {

                 //alert("Selected Type already exists");
                   alert("Select other Type");
                  //document.Form1.all("pre"+i).value=""
                 // document.Form1.all("pre"+i).focus();
                  return false;
                  }

                  else
                  {
                  return true;
                  }

              }
              }

          }//onready


        var url="ValSmpPointPfx.aspx?Prefix=" + SelectedType + "&PointPfxList=" + PointPfxList


     xmlhttp.open("GET",url,true);
     xmlhttp.send(null);

推荐答案

为什么要比较控件?如果您从数据动态创建它们,请比较该数据。



-SA
Why comparing controls? If you create them dynamically from data, compare that data.

—SA


这篇关于如何使用ajax比较两个动态创建的下拉列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆