Hi All,
I'd like to count the no. of selection of multi select combo and describe this count no. into a text box dynamically. how to code?
count multi select combo's selection
Moderator: General Moderators
Re: count multi select combo's selection
You need to give name for select box as an array like "selectbox[]". Now when you submit form you will get its count by "count($_POST['selectbox'])".
Re: count multi select combo's selection
Thanks, Pbs. The counted no. will be dynamically described clicking or selecting the multi-combo's items, not form submitting. Please give me a sample code.
Re: count multi select combo's selection
Hi All,
my web form design has only two controls: a multi combo box and a text box. When user selects the items of this multi combo, its selected count will be described in the text box dynamically. how to code?
my web form design has only two controls: a multi combo box and a text box. When user selects the items of this multi combo, its selected count will be described in the text box dynamically. how to code?
Re: count multi select combo's selection
my code is below:
<td>
<select name="options[]" size="4" multiple >
<option value="magnifier">Magnifier</option>
<option value="reducer">Reducer</option>
<option value="timer">Timer</option>
<option value="oscillator">Oscillator</option>
</select>
<td>
<?php
echo count($_POST['options']);
?>
But this does not work.
<td>
<select name="options[]" size="4" multiple >
<option value="magnifier">Magnifier</option>
<option value="reducer">Reducer</option>
<option value="timer">Timer</option>
<option value="oscillator">Oscillator</option>
</select>
<td>
<?php
echo count($_POST['options']);
?>
But this does not work.
Re: count multi select combo's selection
<select name="ok" id="ok" size="4" multiple onChange="selvalue()" >
<option value="magnifier">Magnifier</option>
<option value="reducer">Reducer</option>
<option value="timer">Timer</option>
<option value="oscillator">Oscillator</option>
</select>
<input name="text" type="text" id="text" value="skdjfksd">
<script>
function selvalue(){
text.value=ok.options[ok.selectedIndex].text
}
</script>
this code can do it, hope can help you! Don't use php code do it. you may do it in "javascript", it's easy!
<option value="magnifier">Magnifier</option>
<option value="reducer">Reducer</option>
<option value="timer">Timer</option>
<option value="oscillator">Oscillator</option>
</select>
<input name="text" type="text" id="text" value="skdjfksd">
<script>
function selvalue(){
text.value=ok.options[ok.selectedIndex].text
}
</script>
this code can do it, hope can help you! Don't use php code do it. you may do it in "javascript", it's easy!
Re: count multi select combo's selection
Thanks All. I get it!
<select name="ok[]" id="ok" size="4" multiple onChange="valList(this);">
<option value="magnifier">Magnifier</option>
<option value="reducer">Reducer</option>
<option value="timer">Timer</option>
<option value="oscillator">Oscillator</option>
</select>
<input name="text" type="text" id="text" value="skdjfksd">
<script>
function valList(thissel){
var selCount = 0;
for (var i=0; i<thissel.length; i++) {
if (thissel.selected) {
selCount += 1;
}
}
text.value= selCount;
}
</script>
<select name="ok[]" id="ok" size="4" multiple onChange="valList(this);">
<option value="magnifier">Magnifier</option>
<option value="reducer">Reducer</option>
<option value="timer">Timer</option>
<option value="oscillator">Oscillator</option>
</select>
<input name="text" type="text" id="text" value="skdjfksd">
<script>
function valList(thissel){
var selCount = 0;
for (var i=0; i<thissel.length; i++) {
if (thissel.selected) {
selCount += 1;
}
}
text.value= selCount;
}
</script>