943,552 Members | Top Members by Rank

Ad:
  • ASP.NET Discussion Thread
  • Unsolved
  • Views: 1777
  • ASP.NET RSS
You are currently viewing page 3 of this multi-page discussion thread; Jump to the first page
Jan 2nd, 2009
0

Re: regarding drpo down list

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

ASP.NET Syntax (Toggle Plain Text)
  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.
Reputation Points: 10
Solved Threads: 0
Light Poster
kodingkarthik is offline Offline
37 posts
since Dec 2008
Jan 2nd, 2009
0

Re: regarding drpo down list

I'm sorry, didn't realize that was a function I built to add an option. Here is the way to add an option:

javascript Syntax (Toggle Plain Text)
  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.
Reputation Points: 43
Solved Threads: 68
Veteran Poster
SheSaidImaPregy is offline Offline
1,080 posts
since Sep 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in ASP.NET Forum Timeline: How to get an excel file while button click.
Next Thread in ASP.NET Forum Timeline: Custom class object question





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC