how to clear the combo box values using javascript..?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • nirmalsingh
    New Member
    • Sep 2006
    • 218

    how to clear the combo box values using javascript..?

    my combo box id is combo1, i want to clear the values that are loaded in combo box from database, plz help me with sample code..
  • b1randon
    Recognized Expert New Member
    • Dec 2006
    • 171

    #2
    Originally posted by nirmalsingh
    my combo box id is combo1, i want to clear the values that are loaded in combo box from database, plz help me with sample code..
    Post some code that we can help you with...

    Comment

    • nirmalsingh
      New Member
      • Sep 2006
      • 218

      #3
      //my coding...
      var strDetails;
      var intLoop;
      var strArrRow = new Array();
      strDetails=xmlH ttp.statusText;//records to load combo..
      strArrRow =strDetails.spl it('|');
      var x=document.getE lementById("com bo1");
      for (intLoop=0;intL oop<strArrRow.l ength-1;intLoop++)
      {
      var y=document.crea teElement('opti on');
      y.text=strArrRo w[intLoop]
      try
      {
      x.add(y, null);
      }
      catch(ex)
      {
      x.add(y);
      }
      }

      Comment

      • r035198x
        MVP
        • Sep 2006
        • 13225

        #4
        Originally posted by nirmalsingh
        //my coding...
        var strDetails;
        var intLoop;
        var strArrRow = new Array();
        strDetails=xmlH ttp.statusText;//records to load combo..
        strArrRow =strDetails.spl it('|');
        var x=document.getE lementById("com bo1");
        for (intLoop=0;intL oop<strArrRow.l ength-1;intLoop++)
        {
        var y=document.crea teElement('opti on');
        y.text=strArrRo w[intLoop]
        try
        {
        x.add(y, null);
        }
        catch(ex)
        {
        x.add(y);
        }
        }
        I'm a bit confused here. Do you want to delete values from the database or do you want to clear options from a select box?

        Comment

        • nirmalsingh
          New Member
          • Sep 2006
          • 218

          #5
          sorry to make u confused sir, i want to clear the options from the select box. not from database.

          Comment

          • r035198x
            MVP
            • Sep 2006
            • 13225

            #6
            Originally posted by nirmalsingh
            sorry to make u confused sir, i want to clear the options from the select box. not from database.
            Well the general rule is if you have a select by the name box, then

            To clear all options of box just do
            box.options.len gth = 0;

            Comment

            • b1randon
              Recognized Expert New Member
              • Dec 2006
              • 171

              #7
              Originally posted by r035198x
              Well the general rule is if you have a select by the name box, then

              To clear all options of box just do
              box.options.len gth = 0;
              This is by far the best way to remove the options. If you try to remove them one by one in a loop you won't be able to remove the last option. I lost a good bit of hair before realizing that options.length= 0; is all I needed :/

              Comment

              • r035198x
                MVP
                • Sep 2006
                • 13225

                #8
                Originally posted by b1randon
                This is by far the best way to remove the options. If you try to remove them one by one in a loop you won't be able to remove the last option. I lost a good bit of hair before realizing that options.length= 0; is all I needed :/
                I hope the hair grew back on.

                Comment

                Working...