943,580 Members | Top Members by Rank

Ad:
Aug 26th, 2008
0

Counter for selectbox

Expand Post »
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
Reputation Points: 38
Solved Threads: 0
Master Poster
veledrom is offline Offline
724 posts
since Apr 2008
Aug 27th, 2008
0

Re: Counter for selectbox

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...
html Syntax (Toggle Plain Text)
  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>
javascript Syntax (Toggle Plain Text)
  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>
html Syntax (Toggle Plain Text)
  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>
Featured Poster
Reputation Points: 114
Solved Threads: 138
Posting Shark
essential is offline Offline
973 posts
since Aug 2008

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 JavaScript / DHTML / AJAX Forum Timeline: horizontal menu
Next Thread in JavaScript / DHTML / AJAX Forum Timeline: displaying image at loading time & display message in success after any operation





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


Follow us on Twitter


© 2011 DaniWeb® LLC