RSS Forums RSS
Please support our JavaScript / DHTML / AJAX advertiser: Lunarpages Web Hosting
Views: 1170 | Replies: 4 | Thread Tools  Display Modes
Reply
Join Date: Aug 2008
Posts: 2
Reputation: nileema is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
nileema nileema is offline Offline
Newbie Poster

add combobox dynamicaly

  #1  
Aug 21st, 2008
hi
I want to add combobox dynamicaly on onclick event of button .
On next page i want to get that selected item of each combo.
How would i get the id each combo?
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Aug 2008
Posts: 197
Reputation: essential is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 28
essential's Avatar
essential essential is online now Online
Junior Poster

Re: add combobox dynamicaly

  #2  
Aug 21st, 2008
This is a quick example on how to create a dynamic dropDown list. I hope this will keep you goin! Enjoy coding...

  1. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  2. <html>
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5. <title>Some Title</title>

  1. <script type="text/javascript">
  2. <!-- BEGIN HIDING
  3.  
  4. function dropDownList()
  5. {
  6. var _items = [ 'item1', 'item2', 'item3', 'item4' ];
  7. var container = document.getElementsByTagName('div')[1];
  8. var _button = document.getElementsByTagName('input')[0];
  9. var _select = document.createElement('select');
  10. for ( var x = 0; x < _items.length; x++ ) {
  11. _option = document.createElement('option');
  12. var _text = document.createTextNode(_items[x]);
  13. _option.appendChild(_text);
  14. _select.appendChild(_option);
  15. _option.value = _items[x]; }
  16. container.appendChild(_select);
  17. _select.setAttribute('name', 'list');
  18. _button.value = 'Show Items!';
  19. _button.setAttribute('onclick', 'showItems(\'items\');');
  20. }
  21. function showItems(id)
  22. {
  23. var itemHolder = document.getElementById(id);
  24. var _list = myform.list.options;
  25. var show_list = '<b>'+ _list[0].value + '<br />';
  26. show_list += _list[1].value +'<br />';
  27. show_list += _list[2].value + '<br />';
  28. show_list += _list[3].value + '</b>';
  29. itemHolder.innerHTML = show_list;
  30.  
  31. }
  32. // DONE HIDING-->
  33. </script>

  1. </head>
  2. <body>
  3. <div>
  4. <form name="myform" onsubmit="return false;">
  5. <div>&nbsp;</div><br />
  6. <input type="button" name="button1" value=" Show Me! " onclick="dropDownList()" />
  7. </form>
  8. </div>
  9. <div id="items">&nbsp;</div>
  10. </body>
  11. </html>
Last edited by essential : Aug 21st, 2008 at 9:52 pm.
The test of a first-rate intelligence is the ability to hold two opposed ideas in the mind at the same time, and still retain the ability to function. One should, for example, be able to see that things are hopeless and yet be determined to make them otherwise.
Reply With Quote  
Join Date: Aug 2008
Posts: 2
Reputation: nileema is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
nileema nileema is offline Offline
Newbie Poster

Re: add combobox dynamicaly

  #3  
Aug 22nd, 2008
Thanx for code, it works!
but i want to add 3 combo dynamicaly on onclick event one after other , when page is reload!
Reply With Quote  
Join Date: Aug 2008
Posts: 197
Reputation: essential is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 28
essential's Avatar
essential essential is online now Online
Junior Poster

Re: add combobox dynamicaly

  #4  
Aug 22nd, 2008
Sorry if i take u this long, am just busy with some other stuff here! So you want a total of 3 combo that add up next after the other when the page is reloaded? Having a 3 combo b4 the page reloads
is quite easy! But if you prefer 3 combo onafter the page is reloaded, then i need to get some extra time 2 work on it! Tnx...
The test of a first-rate intelligence is the ability to hold two opposed ideas in the mind at the same time, and still retain the ability to function. One should, for example, be able to see that things are hopeless and yet be determined to make them otherwise.
Reply With Quote  
Join Date: Aug 2008
Posts: 197
Reputation: essential is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 28
essential's Avatar
essential essential is online now Online
Junior Poster

Re: add combobox dynamicaly

  #5  
Aug 23rd, 2008
Please feel free to modify this code to match your needs. If you have any question regarding this code you can document.write('Me on my inbox'). lol! Have a good day...

  1. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  2. <html>
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5. <title>Creating Dynamic Combo</title>

  1. <style type="text/css">
  2. <!--
  3. *{}
  4. form { margin: 6px; padding: 4px; text-align: left; font-weight: bold; color: dimgrey; }
  5. form select { margin: 6px 0 6px 0; padding: 2px; color: grey; }
  6. form input[type=button] { background-color: black; color: silver; }
  7. -->
  8. </style>

  1. <script type="text/javascript">
  2. <!-- BEGIN HIDING
  3. <!-- ADDING COMBO -->
  4. //--> REMODIFIED <--\\
  5. //You will love this 1 compare to my 1st version!
  6. //This will create 3 combo boxes with 2sec. delay.
  7. //If you wish to load this one by one each time the page reloads.
  8.  
  9. /* just create a cookie function that holds a counter and assign it to the variable n */
  10.  
  11. //Enjoy Coding and bye for now!
  12.  
  13. function AddCombo()
  14. {
  15.  
  16. var _form = document.getElementsByTagName('form')[0];
  17. var _button = document.getElementsByTagName('input')[0];
  18. _button.setAttribute('onclick', 'return false;');
  19. n = 1;
  20. t = setTimeout('AddCombo()', 2000);
  21. t = ( t == 3 ) ? clearTimeout(t) : t;
  22. s = '3';
  23. s = ( t == 1 ) ? '1' : s;
  24. s = ( t == 2 ) ? '2' : s;
  25.  
  26. do
  27. {
  28. items = [ 'Combo' + s + ' Option List 1', 'Combo' + s + ' Option List 2', 'Combo' + s + ' Option List 3' ];
  29.  
  30. _select = document.createElement('select');
  31. for ( var x = 0; x < items.length; x++ ) {
  32. _option = document.createElement('option');
  33. _br = document.createElement('br');
  34. _item = document.createTextNode(items[x]);
  35. _text = document.createTextNode('Selection ' + s );
  36. _option.appendChild(_item);
  37. _select.appendChild(_option);
  38. _text.insertBefore(_select);
  39.  
  40. _option.value = items[x]; }
  41. _form.appendChild(_br);
  42. _form.appendChild(_text);
  43. _form.appendChild(_select);
  44. _select.setAttribute('id', 'select' + s);
  45. n++;
  46. } while( n < t );
  47. }
  48.  
  49. // DONE HIDING -->
  50. </script>

  1. </head>
  2. <body>
  3. <form name="form1" action="#" onsubmit="return false;">
  4. </form><br />
  5. <form name="form2" action="#" onsubmit="return false;">
  6. <input type="button" name="button1" value=" Show Me " onclick="AddCombo();" />
  7. </form>
  8. </body>
  9. </html>
Last edited by essential : Aug 23rd, 2008 at 8:51 am.
The test of a first-rate intelligence is the ability to hold two opposed ideas in the mind at the same time, and still retain the ability to function. One should, for example, be able to see that things are hopeless and yet be determined to make them otherwise.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.



Other Threads in the JavaScript / DHTML / AJAX Forum
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 7:57 pm.
Newsletter Archive - Sitemap - Privacy Statement - Acceptable Use Policy - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC