...

View Full Version : validating multiple radiobuttons with javascript



mrjameer
09-23-2006, 01:23 PM
hi

i want to know how to validate multiple set of radiobuttons.for example
1.item A
a.item1-$100
b.item2-$200
c.item3-$300

2.item B
a.item4-$200
b.item5-$300
c.item6-$400

3.item C
a.item7-$10
b.item8-$20
c.item9-$30

when item1 of itemA is clicked its value should be displayed in one textbox and when 3 items had been selected from three sets of radio buttons its total value should be displayed in same textbox like this.how to do it please help me.

mrjameer

BubikolRamios
09-23-2006, 06:28 PM
look for onClick event from radio

<INPUT type='radio' onClick = '...write your function here'>

Mr J
09-24-2006, 09:50 AM
Please try the following


<HTML>
<HEAD>
<TITLE>Document Title</TITLE>

<script type="text/javascript">
<!--

function chkRads(){

count=0
total=0

myForm=document.f1

while(myForm.elements["r"+count]){
el=myForm.elements["r"+count]


for(var i=0;i<el.length;i++){

if(el[i].checked){
total+=el[i].value*1
}

}

count++

}

document.forms["f1"]["t1"].value=total

}

</script>

</HEAD>
<BODY onload="chkRads()">

<form name="f1">

<input type="radio" value="100" name="r0" onclick="chkRads()" checked> $100<BR>
<input type="radio" value="200" name="r0" onclick="chkRads()"> $200<BR>
<input type="radio" value="300" name="r0" onclick="chkRads()"> $300<BR>

<BR>

<input type="radio" value="200" name="r1" onclick="chkRads()" checked> $200<BR>
<input type="radio" value="300" name="r1" onclick="chkRads()"> $300<BR>
<input type="radio" value="400" name="r1" onclick="chkRads()"> $400<BR>

<BR>

<input type="radio" value="10" name="r2" onclick="chkRads()" checked> $10<BR>
<input type="radio" value="20" name="r2" onclick="chkRads()"> $20<BR>
<input type="radio" value="30" name="r2" onclick="chkRads()"> $30<BR>

<BR>

$ <input type="text" name="t1">

</form>

</BODY>
</HTML>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum