PDA

View Full Version : check boxes



rama1977
03-16-2006, 07:15 PM
Hi,

I have a check box group.I need to extract the values of each of the checkboxes and also find the maximum value and store it in a hidden variable.Please find the check boxes below.

<input name='manager' type="checkbox" onclick="return changeManager(this);" value='a_100'> Robin<br>

<input name='manager' type="checkbox" onclick="return changeManager(this);" value='b_100'> John<br>


<input name='manager' type="checkbox" onclick="return changeManager(this);" value='c_400'> Smith<br>


What i need is if the user clicks the check boxes i need to extract the values after the '-' say for example the values 100,100,400 and also the greater of them should be stored in a hidden variable.If the user removes a check box then i have delete them from the array and find the greatest of them afain.Let me know how i can do that.


Thnx

Twey
03-16-2006, 07:42 PM
What's the point of the whole a_ b_ c_ thing?

<script type="text/javascript">
String.prototype.getNumberFromOddValue = function() {
return parseInt(this.substr(this.lastIndexOf("_") + 1));
}
var getMaxVal = function(boxes) {
var e = boxes,
currMax = e[0].value.getNumberFromOddValue();
for(var i = 0; i < e.length; i++) if(e[i].value.getNumberFromOddValue() < currMax && e[i].checked) currMax = e[i].value.getNumberFromOddValue();
return currMax;
}
</script>

<input name='manager' type="checkbox" onclick="this.form.elements['biggest'].value=getMaxVal(document.getElementsByName(this.name));return changeManager(this);" value='a_100'> Robin<br>

<input name='manager' type="checkbox" onclick="this.form.elements['biggest'].value=getMaxVal(document.getElementsByName(this.name));return changeManager(this);" value='b_100'> John<br>

<input name='manager' type="checkbox" onclick="this.form.elements['biggest'].value=getMaxVal(document.getElementsByName(this.name));return changeManager(this);" value='c_400'> Smith<br>

<input name="biggest" type="hidden" value="0"> Untested.