By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
460,045 Members | 1,339 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 460,045 IT Pros & Developers. It's quick & easy.

remove all listitems using javascript

P: 94
Hi,
Can anyone Help. I have two dropdownlist for qualification and degree.
According to the qualification(eg.Diploma,UG,PG) degree gets binded in the dropdownlist. I have done this in javascript.It works fine but the values binded early does not get cleared. How to remove previously binded items and rebind with new Items.If any corrections i Have to do then please tell me.Urgent. I await for reply.
My code is

// Items is an array like
items[0] = "Value","Text"
Expand|Select|Wrap|Line Numbers
  1. function OnGetDegree(Items)
  2. {
  3.  
  4. var e = document.getElementById ("ctl00_ContentPlaceHolder1_ddlDegree");
  5. //var length = e.options.length;
  6. //code to remove items (not working correctly)
  7. if(e.options.length > 0)
  8. {
  9.     var count;
  10.     for (count = 0 ; count < e.options.length ; count++)
  11.     {    
  12.     e.remove(count);
  13.     }
  14. }[indent]for(i=0;i<Items.length;i++)
  15. {
  16. var options = Items[i].split(",");
  17. var o = document.createElement("option");
  18. o.text = options[1];  // text
  19. o.value = options[0];  // value
  20. e.add(o);
  21. }
  22. }

With Thanks & regards,

Sudha
Oct 9 '07 #1
Share this Question
Share on Google+
8 Replies


dmjpro
100+
P: 2,476
Hi,
Can anyone Help. I have two dropdownlist for qualification and degree.
According to the qualification(eg.Diploma,UG,PG) degree gets binded in the dropdownlist. I have done this in javascript.It works fine but the values binded early does not get cleared. How to remove previously binded items and rebind with new Items.If any corrections i Have to do then please tell me.Urgent. I await for reply.
My code is

// Items is an array like
items[0] = "Value","Text"
Expand|Select|Wrap|Line Numbers
  1. function OnGetDegree(Items)
  2. {
  3.  
  4. var e = document.getElementById ("ctl00_ContentPlaceHolder1_ddlDegree");
  5. //var length = e.options.length;
  6. //code to remove items (not working correctly)
  7. if(e.options.length > 0)
  8. {
  9.     var count;
  10.     for (count = 0 ; count < e.options.length ; count++)
  11.     {    
  12.     e.remove(count);
  13.     }
  14. }
[indent]for(i=0;i<Items.length;i++)
  • {
  • var options = Items[i].split(",");
  • var o = document.createElement("option");
  • o.text = options[1];  // text
  • o.value = options[0];  // value
  • e.add(o);
  • }
  • }

  • With Thanks & regards,

    Sudha I faced this problem once...and got it work.
    Have a look at your fragment of your code.

    Expand|Select|Wrap|Line Numbers
    1. if(e.options.length > 0)
    2. {
    3.     var count=0;
    4.     for ( ; count < e.options.length ; count++)
    5.     {   
    6.     e.remove(count);
    7.     count = 0;
    8.     }
    9. }
    10.  
    Enjoy this code.
    Good Luck !

    Debasis Jana
    Oct 9 '07 #2

    dmjpro
    100+
    P: 2,476
    Hi,
    Can anyone Help. I have two dropdownlist for qualification and degree.
    According to the qualification(eg.Diploma,UG,PG) degree gets binded in the dropdownlist. I have done this in javascript.It works fine but the values binded early does not get cleared. How to remove previously binded items and rebind with new Items.If any corrections i Have to do then please tell me.Urgent. I await for reply.
    My code is

    // Items is an array like
    items[0] = "Value","Text"
    Expand|Select|Wrap|Line Numbers
    1. function OnGetDegree(Items)
    2. {
    3.  
    4. var e = document.getElementById ("ctl00_ContentPlaceHolder1_ddlDegree");
    5. //var length = e.options.length;
    6. //code to remove items (not working correctly)
    7. if(e.options.length > 0)
    8. {
    9.     var count;
    10.     for (count = 0 ; count < e.options.length ; count++)
    11.     {    
    12.     e.remove(count);
    13.     }
    14. }
    [indent]for(i=0;i<Items.length;i++)
  • {
  • var options = Items[i].split(",");
  • var o = document.createElement("option");
  • o.text = options[1];  // text
  • o.value = options[0];  // value
  • e.add(o);
  • }
  • }

  • With Thanks & regards,

    Sudha You can achieve it using......

    Expand|Select|Wrap|Line Numbers
    1. e.options.length = 0; //enjoy .....
    2.  
    Debasis Jana
    Oct 9 '07 #3

    P: 94
    You can achieve it using......

    Expand|Select|Wrap|Line Numbers
    1. e.options.length = 0; //enjoy .....
    2.  
    Debasis Jana

    Thanks. I try and then send reply to you.
    Oct 9 '07 #4

    dmjpro
    100+
    P: 2,476
    Thanks. I try and then send reply to you.
    Please check your PM.

    Debasis Jana
    Oct 9 '07 #5

    P: 94
    Please check your PM.

    Debasis Jana

    Hi Jana,
    Thanks a lot. With the first code you provided i still faced some problems. But the second code ''e.options.length = 0" worked fine.Thank you very much.

    Cheers.
    Sudha
    Oct 9 '07 #6

    dmjpro
    100+
    P: 2,476
    Hi Jana,
    Thanks a lot. With the first code you provided i still faced some problems. But the second code ''e.options.length = 0" worked fine.Thank you very much.

    Cheers.
    Sudha
    Sorry that will be ....
    Expand|Select|Wrap|Line Numbers
    1. if(e.options.length > 0)
    2. {
    3.     var count=0;
    4.     for ( ; count < e.options.length ;)
    5.     {   
    6.     e.remove(count);
    7.     count = 0;
    8.     }
    9. }
    10.  
    Have a try with this .......

    Debasis Jana
    Oct 9 '07 #7

    P: 94
    Sorry that will be ....
    Expand|Select|Wrap|Line Numbers
    1. if(e.options.length > 0)
    2. {
    3.     var count=0;
    4.     for ( ; count < e.options.length ;)
    5.     {   
    6.     e.remove(count);
    7.     count = 0;
    8.     }
    9. }
    10.  
    Have a try with this .......

    Debasis Jana

    Hi,

    You are very good in javascript. This code also worked fine.
    Thanks for your immediate response. I was spending half day for this.

    Bye,
    Sudha
    Oct 9 '07 #8

    dmjpro
    100+
    P: 2,476
    Hi,

    You are very good in javascript. This code also worked fine.
    Thanks for your immediate response. I was spending half day for this.

    Bye,
    Sudha
    If you are online, then check your private messages (PM).
    You know it?

    Debasis jana
    Oct 9 '07 #9

    Post your reply

    Sign in to post your reply or Sign up for a free account.