regarding drpo down list

Please support our ASP.NET advertiser: Intel Parallel Studio Home
Reply

Join Date: Dec 2008
Posts: 37
Reputation: kodingkarthik is an unknown quantity at this point 
Solved Threads: 0
kodingkarthik kodingkarthik is offline Offline
Light Poster

Re: regarding drpo down list

 
0
  #21
Jan 2nd, 2009
Hi SheSaidImaPregy,

Thanks for your reply but i am not able to understand the logic behind the code for "focus()" method. What u said is correct i am getting an error with the following code

  1. <script type="text/javascript">
  2. function chkChange(ddl)
  3. {
  4. var textbox = document.getElementById("<%= txtdept.ClientID %>");
  5.  
  6. if (ddl.options[ddl.selectedIndex].value == "New Department")
  7. {
  8. textbox.style.display = "block";
  9. }
  10. else
  11. {
  12. textbox.style.display = "none";
  13. }
  14. document.getElementById("<%= ddldept.ClientID %>").options.add(new Option(index, "value", "text"));
  15. }
  16. </script>

Help please
Thank u.
Reply With Quote Quick reply to this message  
Join Date: Sep 2007
Posts: 1,080
Reputation: SheSaidImaPregy is an unknown quantity at this point 
Solved Threads: 68
SheSaidImaPregy SheSaidImaPregy is offline Offline
Veteran Poster

Re: regarding drpo down list

 
0
  #22
Jan 2nd, 2009
I'm sorry, didn't realize that was a function I built to add an option. Here is the way to add an option:

  1. <script type="text/javascript">
  2. function chkChange(ddl)
  3. {
  4. var textbox = document.getElementById("<%= txtdept.ClientID %>");
  5.  
  6. if (ddl.options[ddl.selectedIndex].value == "New Department")
  7. {
  8. elm.onblur = function() { addOptionOnBlur(this); };
  9. textbox.style.display = "block";
  10. textbox.focus();
  11. }
  12. else
  13. {
  14. textbox.style.display = "none";
  15. }
  16. }
  17.  
  18. function addOptionOnBlur(elm)
  19. {
  20. if (elm.value.length > 0 && elm.value.replace(/ /g, "").length > 0)
  21. {
  22. document.getElementById("<%= ddldept.ClientID %>").options.add(newOption(elm.value, elm.value));
  23. }
  24. }
  25.  
  26. function newOption(val, txt)
  27. {
  28. var option = document.createElement("OPTION");
  29. option.text = txt;
  30. option.value = val;
  31.  
  32. return option;
  33. }
  34. </script>

This will add an option to the dropdownlist everytime the textbox loses focus, as long as the value is empty and isn't only spaces.
I answer pm's.
I answer questions.
I answer quickly.
I answer.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the ASP.NET Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC