RSS Forums RSS

Counter for selectbox

Please support our JavaScript / DHTML / AJAX advertiser: Programming Forums
Reply
Posts: 429
Reputation: veledrom is an unknown quantity at this point 
Solved Threads: 0
veledrom veledrom is offline Offline
Posting Pro in Training

Counter for selectbox

  #1  
Aug 26th, 2008
Hi,

How do we increase and decrease a counter when we click on a selectbox?
Example: I have 3 selectbox. Whenever i click on one selectbox it will print on screen a message 1 selected, 2 selected 3.......

Thank you very much
AddThis Social Bookmark Button
Reply With Quote  
Posts: 730
Reputation: essential is on a distinguished road 
Solved Threads: 104
Featured Poster
Featured Coder
essential's Avatar
essential essential is offline Offline
Master Poster

Re: Counter for selectbox

  #2  
Aug 27th, 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>Some Title</titles>
  1. <script type="text/javascript">
  2. <!-- BEGIN HIDING
  3.  
  4. /* A simple counter script that will generate each the user select any option in the comboBox! */
  5.  
  6. var i = 0;
  7. var x = 0;
  8.  
  9. function _selected()
  10. {
  11. if ( form1.myselect.options[0].selected ) { i = i + 1;
  12. form1.myselect.options[0].text = 'Count ' + i; }
  13. if ( form1.myselect.options[1].selected ) { x = x + 1;
  14. form1.myselect.options[1].text = 'Count ' + x; }
  15. if ( i == 5 || x == 5 ) { alert('\nThat\'s enough for now');
  16. i = ( i == 5 ) ? 0 : i;
  17. x = ( x == 5 ) ? 0 : x;
  18. }
  19. }
  20. // DONE HIDING -->
  21. </script>
  1. </head>
  2. <body>
  3.  
  4. <form name="form1" action="#" onsubmit="return false;">
  5. <select id="myselect" onchange="_selected();">
  6. <option value="">selection1</option>
  7. <option value="">selection2</option>
  8. </select>
  9. </form>
  10. </body>
  11. </html>
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
Views: 657 | Replies: 1 | Currently Viewing: 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 3:47 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