Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Aug 2006
    Posts
    133
    Thanks
    0
    Thanked 0 Times in 0 Posts

    validating multiple radiobuttons with javascript

    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

  • #2
    Senior Coder
    Join Date
    Dec 2005
    Location
    Slovenia
    Posts
    1,994
    Thanks
    120
    Thanked 76 Times in 76 Posts
    look for onClick event from radio

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

  • #3
    Senior Coder
    Join Date
    Aug 2002
    Location
    UK
    Posts
    2,789
    Thanks
    2
    Thanked 14 Times in 14 Posts
    Please try the following

    PHP Code:
    <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> 
    The silent one.

    The most dangerous thing in the world is an idea.
    The most dangerous person in the world is the one with an idea.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •