www.webdeveloper.com
Results 1 to 4 of 4

Thread: Please this code suppose to work but isnt?

  1. #1
    Join Date
    Jul 2012
    Posts
    6

    Please this code suppose to work but isnt?

    <script type="text/javascript">
    /*<CDATA[[*/
    function g1(){
    for (i = 0; i < document.forms[0].g2.length; ++i){
    if(document.forms[0].g2[i].ckecked == true){
    document.forms[0].g2[i].checked = false;
    }
    }
    }
    function g2(){
    for (i = 0; i < document.forms[0].g1.length; ++i){
    if(document.forms[0].g1[i].checked == true){
    document.forms[0].g1[i].checked = false;
    }
    }

    }
    /*]]>*/
    </script>
    </head>
    <body>
    <form action="" method="" enctype="application/x-www-form-urlencoded" >
    <b>Group 1</b><br />
    <input type="radio" name="g1" onclick="g1()" />
    <input type="radio" name="g1" onclick="g1()" /><br />
    <b>Goutp 2</b><br />
    <input type="radio" name="g2" onclick="g2()" />
    <input type="radio" name="g2" onclick="g2()" />
    </form>

    By checking either of the radio button, the rest should be un-checked...

  2. #2
    Join Date
    Dec 2005
    Location
    FL
    Posts
    7,354

    Lightbulb

    I'm not sure I understand the purpose of the two functions resetting the other group.
    This could be handled easier by making the radio buttons as a single name
    Here is your code and my code side-by-side.
    Code:
    <script type="text/javascript">
    function fg1(){
     for (i = 0; i < document.forms[0].g2.length; ++i){
      document.forms[0].g2[i].checked = false;
     }
    }
    function fg2(){
     for (i = 0; i < document.forms[0].g1.length; ++i){
      document.forms[0].g1[i].checked = false;
     }
    }
    </script>
    </head>
    <body>
    <form action="" method="" enctype="application/x-www-form-urlencoded" >
    <div style="width:25&#37;;float:left;border:1px solid red">
    <b>Group 1</b><br />
    <input type="radio" name="g1" onclick="fg1()" />
    <input type="radio" name="g1" onclick="fg1()" /><br />
    <b>Goutp 2</b><br />
    <input type="radio" name="g2" onclick="fg2()" />
    <input type="radio" name="g2" onclick="fg2()" />
    </div>
    
    <div style="width:25%;float:left;border:1px solid blue">
    <b>Group 1</b><br />
    <input type="radio" name="g12" />
    <input type="radio" name="g12" /><br />
    <b>Goutp 2</b><br />
    <input type="radio" name="g12" />
    <input type="radio" name="g12" />
    </div>
    
    </form>

  3. #3
    Join Date
    Jul 2012
    Posts
    6
    Code:
    <script type="text/javascript">
    /*<CDATA[[*/
    
    function billAutomatically(){
    for (var count = 0; count < document.forms[0].delivery.length; ++count){
    if(document.forms[0].delivery[count].checked == true){
    	document.forms[0]delivery.checked = false;
    	break;
    }
    }
    }
    function billByIssue(){
    for (var count = 0; count < document.forms[0].autoRenew.length; ++count){
    if(document.forms[0].autoRenew[count].checked == true){
    	document.forms[0].autoRenew.checked = false;
    	break;
    }
    }
    }
    </script>
    </head>
    <body>
    <form action="" method="" enctype="application/x-www-form-urlencoded" >
    <h3>Delivery Rates</h3>
    <table>
    <colgroup align="left" width="100" />
    <colgroup span="4" align="center" width="100" />
    <tr>
    <th>6 issues</th>
    <th>12 issues</th>
    <th>18 issues</th>
    <th>24 issues</th></tr>
    <tr>
    <td><input type="radio" name="delivery" value="17.50" onclick="billByIssue();"/>$17.50</td>
    <td><input type="radio" name="delivery" value="26.95" onclick="billByIssue();"/>$26.95</td>
    <td><input type="radio" name="delivery" value="32.90" onclick="billByIssue();"/>$32.90</td>
    <td><input type="radio" name="delivery" value="46.00" onclick="billByIssue();"/>$46.00</td></tr> 
    </table>
    <p>
    	<strong>Automatic Renewal</strong>
    	<input type="radio" name="autoRenew" onclick="billAutomatically();" />Monthly ($8.95)
    	<input type="radio" name="autoRenew" onclick="billAutomatically();" />Yearly ($19.95)</p>
    
    </form>
    if u click, for instance, either of the monthly(8.95) or yearly(19.95) radio buttons, all the other radio buttons in this script should be deselected(un-checked).. Likewise, if u click one of the "issues" radio button, the reset (including the monthly, and yearly) of the radio button should be un checked.

    hope now u understand, thanks.

  4. #4
    Join Date
    Dec 2005
    Location
    FL
    Posts
    7,354

    Exclamation

    I still do not see what benefit you get from two different groups of radio buttons.

    Since all the values are different, you would be able to tell the subscription rates just by that information only
    and still need only one radio button group to achieve the functions you describe.

    Code:
    <script type="text/javascript">
    
    </script>
    </head>
    <body>
    <form action="" method="" enctype="application/x-www-form-urlencoded" >
    <h3>Delivery Rates</h3>
    <table>
    <colgroup align="left" width="100" />
    <colgroup span="4" align="center" width="100" />
    <tr>
    <th>6 issues</th>
    <th>12 issues</th>
    <th>18 issues</th>
    <th>24 issues</th>
    </tr>
    <tr>
    <td><input type="radio" name="delivery" value="17.50" />$17.50</td>
    <td><input type="radio" name="delivery" value="26.95" />$26.95</td>
    <td><input type="radio" name="delivery" value="32.90" />$32.90</td>
    <td><input type="radio" name="delivery" value="46.00" />$46.00</td></tr> 
    </table>
    <p>
    	<strong>Automatic Renewal</strong><p />
    	<input type="radio" name="delivery" value="8.95" /><b>Monthly</b> ($8.95)
    	<input type="radio" name="delivery" value="19.95" /><b>Yearly</b> ($19.95)</p>
    
    </form>

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

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



Recent Articles