ListItems added using Js gets cleared on Page load?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sudhaMurugesan
    New Member
    • May 2007
    • 94

    ListItems added using Js gets cleared on Page load?

    Hi ALL,
    I am binding ListItems to dropdownlist using js.But the selected value is not retained while save operation. Do I need to capture the selected Item in any hiddenfields ?
    plz tell me

    Sudha
  • dmjpro
    Top Contributor
    • Jan 2007
    • 2476

    #2
    Originally posted by sudhaMurugesan
    Hi ALL,
    I am binding ListItems to dropdownlist using js.But the selected value is not retained while save operation. Do I need to capture the selected Item in any hiddenfields ?
    plz tell me

    Sudha
    Your save operation gets processed properly or it stops to do that?
    Let me know.
    I think when you submit the page then according to browser settings this happnes.
    I think it should not harm your page submitting.

    Debasis Jana

    Comment

    • sudhaMurugesan
      New Member
      • May 2007
      • 94

      #3
      Originally posted by dmjpro
      Your save operation gets processed properly or it stops to do that?
      Let me know.
      I think when you submit the page then according to browser settings this happnes.
      I think it should not harm your page submitting.

      Debasis Jana
      This is my Code. I dont know why this is happening its due to Ajax or due to any wrong with my code
      Code:
      function Major()
      {
      var deg = document.getElementById ("ctl00_ContentPlaceHolder1_ddlDegree");
      
       if(deg.selectedIndex != 0)
          {
          AjaxWebService.GetMajor(deg.options[deg.selectedIndex].value,OnGetMajor);       
          }
          
      }
      function OnGetMajor(Items)
      {
      
      var major = document.getElementById ("ctl00_ContentPlaceHolder1_ddlMajor");
      if(major.options.length > 0)
      {
      major.options.length = 0;// to remove previously binded items
      }
      var o = document.createElement("option");
      o.text = "----Select----";
      o.value = 0;
      major.add(o);
      for(i=0;i<Items.length;i++)
      {
      var options = Items[i].split(",");
      var o = document.createElement("option");
      o.text = options[1];
      o.value = options[0];
      major.add(o);
      }
      }
      Can you find out?

      Comment

      • sudhaMurugesan
        New Member
        • May 2007
        • 94

        #4
        Originally posted by dmjpro
        Your save operation gets processed properly or it stops to do that?
        Let me know.
        I think when you submit the page then according to browser settings this happnes.
        I think it should not harm your page submitting.

        Debasis Jana
        I have kept these fields mandatory and only if these listitems are not null it will get saved. But the listitems are getting cleared during page load.

        Comment

        • dmjpro
          Top Contributor
          • Jan 2007
          • 2476

          #5
          Originally posted by sudhaMurugesan
          This is my Code. I dont know why this is happening its due to Ajax or due to any wrong with my code
          Code:
          function Major()
          {
          var deg = document.getElementById ("ctl00_ContentPlaceHolder1_ddlDegree");
          
           if(deg.selectedIndex != 0)
              {
              AjaxWebService.GetMajor(deg.options[deg.selectedIndex].value,OnGetMajor);       
              }
              
          }
          function OnGetMajor(Items)
          {
          
          var major = document.getElementById ("ctl00_ContentPlaceHolder1_ddlMajor");
          if(major.options.length > 0)
          {
          major.options.length = 0;// to remove previously binded items
          }
          var o = document.createElement("option");
          o.text = "----Select----";
          o.value = 0;
          major.add(o);
          for(i=0;i<Items.length;i++)
          {
          var options = Items[i].split(",");
          var o = document.createElement("option");
          o.text = options[1];
          o.value = options[0];
          major.add(o);
          }
          }
          Can you find out?
          At which point your Ajax Call made and where your "Select Box" gets cleared?
          Let me know ... Quick!

          Debasis Jana

          Comment

          • dmjpro
            Top Contributor
            • Jan 2007
            • 2476

            #6
            Originally posted by sudhaMurugesan
            I have kept these fields mandatory and only if these listitems are not null it will get saved. But the listitems are getting cleared during page load.
            What do you mean by "Page Load"?
            What is your sever side Script?

            Debasis Jana

            Comment

            • sudhaMurugesan
              New Member
              • May 2007
              • 94

              #7
              Originally posted by dmjpro
              At which point your Ajax Call made and where your "Select Box" gets cleared?
              Let me know ... Quick!

              Debasis Jana
              onchange event of degree, i have called the js.In that code only i'm calling ajax;
              But i trying to find where actually listitems is getting cleared

              Comment

              • dmjpro
                Top Contributor
                • Jan 2007
                • 2476

                #8
                Originally posted by sudhaMurugesan
                onchange event of degree, i have called the js.In that code only i'm calling ajax;
                But i trying to find where actually listitems is getting cleared
                If you are using J2EE container ...... then you can post your whole code.
                Means the the "Server Side Script" and the JavaScript File.
                So that I can do test.
                Or you can send me your generated HTML file.
                Your Client Side Script is HTML or something else?

                Debasis Jana

                Comment

                • sudhaMurugesan
                  New Member
                  • May 2007
                  • 94

                  #9
                  Originally posted by dmjpro
                  If you are using J2EE container ...... then you can post your whole code.
                  Means the the "Server Side Script" and the JavaScript File.
                  So that I can do test.
                  Or you can send me your generated HTML file.
                  Your Client Side Script is HTML or something else?

                  Debasis Jana
                  Its ASP.net. I am doubting In this part of the code.

                  Code:
                  function Major()
                  {
                  var deg = document.getElementById ("ctl00_ContentPlaceHolder1_ddlDegree");
                  
                   if(deg.selectedIndex != 0)
                      {
                      AjaxWebService.GetMajor(deg.options[deg.selectedIndex].value,OnGetMajor);       
                      }
                      
                  }
                  function OnGetMajor(Items)
                  {
                  
                  var major = document.getElementById ("ctl00_ContentPlaceHolder1_ddlMajor");
                  [B][I]if(major.options.length > 0)
                  {
                  major.options.length = 0;// to remove previously binded items
                  }[/I][/B]
                  var o = document.createElement("option");
                  o.text = "----Select----";
                  o.value = 0;
                  major.add(o);
                  for(i=0;i<Items.length;i++)
                  {
                  var options = Items[i].split(",");
                  var o = document.createElement("option");
                  o.text = options[1];
                  o.value = options[0];
                  major.add(o);
                  }
                  }

                  Comment

                  • dmjpro
                    Top Contributor
                    • Jan 2007
                    • 2476

                    #10
                    Originally posted by sudhaMurugesan
                    Its ASP.net. I am doubting In this part of the code.

                    Code:
                    function Major()
                    {
                    var deg = document.getElementById ("ctl00_ContentPlaceHolder1_ddlDegree");
                    
                     if(deg.selectedIndex != 0)
                        {
                        AjaxWebService.GetMajor(deg.options[deg.selectedIndex].value,OnGetMajor);       
                        }
                        
                    }
                    function OnGetMajor(Items)
                    {
                    
                    var major = document.getElementById ("ctl00_ContentPlaceHolder1_ddlMajor");
                    [B][I]if(major.options.length > 0)
                    {
                    major.options.length = 0;// to remove previously binded items
                    }[/I][/B]
                    var o = document.createElement("option");
                    o.text = "----Select----";
                    o.value = 0;
                    major.add(o);
                    for(i=0;i<Items.length;i++)
                    {
                    var options = Items[i].split(",");
                    var o = document.createElement("option");
                    o.text = options[1];
                    o.value = options[0];
                    major.add(o);
                    }
                    }
                    Ok let me understand your code.
                    You have two "Select Box"s ..... "onchange" event of "degree" the major gets cleared and refilled with new one, what you get from Server Side.
                    This is what happening.
                    Up to this I am right ?
                    Now tell me what is being cleared?
                    Here I am not getting your Point.

                    Debasis Jana.

                    Comment

                    • sudhaMurugesan
                      New Member
                      • May 2007
                      • 94

                      #11
                      I am suspecting that the error is due to the function called in page load, clearing every thing.I try and then let u know . Sorry for disturbing your valuable time.You actually got my question. Thanks for ur suggestions due to which i can trace my errors. I am working on it. I think it will be cleared.

                      Comment

                      • dmjpro
                        Top Contributor
                        • Jan 2007
                        • 2476

                        #12
                        Originally posted by sudhaMurugesan
                        I am suspecting that the error is due to the function called in page load, clearing every thing.I try and then let u know . Sorry for disturbing your valuable time.You actually got my question. Thanks for ur suggestions due to which i can trace my errors. I am working on it. I think it will be cleared.
                        Then check out your "PageLoad" function.

                        Debasis Jana

                        Comment

                        • sudhaMurugesan
                          New Member
                          • May 2007
                          • 94

                          #13
                          Originally posted by dmjpro
                          Then check out your "PageLoad" function.

                          Debasis Jana
                          Sorry Jana error is with my code only.
                          I am getting Listitems for Major from the selected degree.
                          During PageLoad this degree is null. so my major selection box got cleared. this what happened. I troubled u alot . Sorry.

                          Comment

                          • dmjpro
                            Top Contributor
                            • Jan 2007
                            • 2476

                            #14
                            Originally posted by sudhaMurugesan
                            Sorry Jana error is with my code only.
                            I am getting Listitems for Major from the selected degree.
                            During PageLoad this degree is null. so my major selection box got cleared. this what happened. I troubled u alot . Sorry.
                            What do you mean by this "During PageLoad this degree is null"?
                            Please Clarify me here.
                            And post your "PageLoad" function.
                            Let me have a look here.

                            Debasis Jana

                            Comment

                            • sudhaMurugesan
                              New Member
                              • May 2007
                              • 94

                              #15
                              Originally posted by dmjpro
                              What do you mean by this "During PageLoad this degree is null"?
                              Please Clarify me here.
                              And post your "PageLoad" function.
                              Let me have a look here.

                              Debasis Jana
                              I myself confused a lot. I dont know what was happening. I give you my whole code sir. you please check where i am wrong.But please give me some time to explain u what i'm really doing.

                              Comment

                              Working...