Radio Button


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: Radio Button

  1. #1
    Join Date
    Jan 2006
    Posts
    12

    Radio Button

    Hi Michael and others,
    I have 3 radiobuttons and corresponding 3 textboxes and a submit button. if i choose the 1st radiobutton it shoud disable the 3rd textbox, if i click the second rb 2nd textbox should be disabled and 3 rb should disable 1st tf. The script i need in such a way that the user should not be allowed to go to next page if any one of the enabled textfield is empty.

    Balen

  2. #2
    Join Date
    Dec 2004
    Posts
    717
    Hi Balen,

    Sorry. I didnt' see your post.

    if any one of the enabled textfield is empty.
    "the enabled textfield is empty" means that all textboxes are disabled?

    If Yes, Please check the following coding.
    - If you choose opt1, txt3 will be disabled. (the rest oftextboxes will be enabled.)
    - If you choose opt2, txt2 will be disabled.(the rest oftextboxes will be enabled.)
    - If you choose opt3, txt1 will be disabled.(the rest oftextboxes will be enabled.)

    - If you dont select any option (radio box), (otherwise, if the disable properties of all textboxes are enabled.), the form won't be submitted to other page.



    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" >
    
    <head>
    <meta http-equiv="Content-Language" content="en-us">
    <meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
    <meta name="GENERATOR" content="Microsoft FrontPage 4.0">
    <meta name="ProgId" content="FrontPage.Editor.Document">
    <title>New Page 1</title>
    </head>
    <script language="javascript">
     function setEnabled(id,txtId,value){
       if(!enabledAllTextboxes()){
         alert("There is some errors in the coding.");
         return;
       }     
       var oTextBox = document.getElementById(txtId);
       oTextBox.disabled = true;
     }
     
     function enabledAllTextboxes() {
      try{
       var all = document.all ? document.all.tags("input") : document.getElementsByTagName('input');
       for (var i = 0; i < all.length; i++)    
          if(all[i].type == 'text')all[i].disabled = false;
       
       return true;     
      }
      catch(ex){
        return false;
      }
    }
    function validated(){
      try{
       var all = document.all ? document.all.tags("input") : document.getElementsByTagName('input');
       for (var i = 0; i < all.length; i++)    
          if(all[i].type == 'text'){
            if(all[i].disabled)
              return true;
          }
       
       return false;     
      }
      catch(ex){
        return false;
      }
    }
    </script>
    <body >
    
    <form method="POST" action="http://www.google.com" onsubmit="return validated();">
      <!--webbot bot="SaveResults" U-File="fpweb:///_private/form_results.txt"
      S-Format="TEXT/CSV" S-Label-Fields="TRUE" -->
      <p><input type="radio" value="V1" name="opt1" id="ipt1" onclick="setEnabled(this,'text3',false);">&nbsp; <input type="text1" name="text1" id="text1" size="20" value="1st One"></p>
      <p><input type="radio" value="V2" name="opt1" id="Radio1" onclick="setEnabled(this,'text2',false);">&nbsp; <input type="text" name="text2" id="text2" size="20" value="2nd One"></p>
      <p><input type="radio" value="V3" name="opt1" id="Radio2" onclick="setEnabled(this,'text1',false);">&nbsp; <input type="text3" name="text3" id="text3" size="20" value="3rd One"></p>
      <p><input type="submit" value="Submit" name="B1"><input type="reset" value="Reset" name="B2"></p>
    </form>
    
    </body>
    
    </html>
    Hope it would help..
    Best Regards,
    Michael Sync
    http://michaelsync.net

    The more you share,The more you get

  3. #3
    Join Date
    Aug 2006
    Posts
    1
    Hi All,

    I'm a newbie here..how about if I have 3 radiobuttons and each radio button will correspond to some checkboxes. Then each checkbox will correspond to 1 textbox once this checkbox being selected. How i'm going to do that?

    Your help is much appreciated.

    Thanks

Similar Threads

  1. radio button inside datagrid
    By Balaji N.S in forum .NET
    Replies: 3
    Last Post: 02-17-2007, 03:36 PM
  2. Need help with calculator...
    By 2eXtreme in forum Java
    Replies: 0
    Last Post: 04-05-2006, 08:38 AM
  3. button listener not working
    By DrunkinP in forum Java
    Replies: 0
    Last Post: 03-31-2005, 10:36 AM
  4. Radio Button Problem.
    By Ravindra in forum ASP.NET
    Replies: 1
    Last Post: 05-13-2003, 12:56 AM
  5. Replies: 0
    Last Post: 10-11-2002, 02:16 PM

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
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center