DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   JavaScript / DHTML / AJAX (http://www.daniweb.com/forums/forum117.html)
-   -   Counter for selectbox (http://www.daniweb.com/forums/thread142363.html)

veledrom Aug 26th, 2008 8:59 am
Counter for selectbox
 
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

essential Aug 27th, 2008 5:29 am
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...
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Some Title</titles>
<script type="text/javascript">
<!-- BEGIN HIDING

/* A simple counter script that will generate each the user select any option in the comboBox! */

var i = 0;
var x = 0;

function _selected()
{
if ( form1.myselect.options[0].selected ) { i = i + 1; 
form1.myselect.options[0].text = 'Count ' + i; }
if ( form1.myselect.options[1].selected ) { x = x + 1;
form1.myselect.options[1].text = 'Count ' + x; }
if ( i == 5 || x == 5 ) { alert('\nThat\'s enough for now');
 i = ( i == 5 ) ? 0 : i;
x = ( x == 5 ) ? 0 : x;
  } 
}
// DONE HIDING -->
</script>
</head>
<body>

<form name="form1" action="#" onsubmit="return false;">
<select id="myselect" onchange="_selected();">
<option value="">selection1</option>
<option value="">selection2</option>
</select>
</form>
</body>
</html>


All times are GMT -4. The time now is 9:05 pm.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC