JavaScript - Disabling the radio button.

Asked By anil namburi
25-Feb-11 05:46 AM
Hi iam Using HTML radio button code in jsp page for disabling the radio button.

<input type="radio" id="emActivationYes" name="radio1" value="yes" disabled="disabled" onclick="displayDateFields()" checked>Yes

<input type="radio" id="emActivationNo" name="radio1" value="no" disabled="disabled" onclick="hideDateFields1()" >No .
but this is not working.

I also placed the  java scrpit code to disable the radio button but still it is not working shown below.. can u please provide any other alternative way to disable the radio button.

function onSelectTest1() {

document.getElementById('emActivationYes').disabled=true;

document.frmRequestProject.radio1[0].disabled=true;

document.frmRequestProject.radio1[1].disabled=true;

document.getElementById('emActivationNo').disabled=true;

 

}

  Reena Jain replied to anil namburi
25-Feb-11 05:56 AM
hi,

here is the complete code for you

<HTML>
<HEAD>
<title>WebForm4</title>
<meta name="GENERATOR" content="Microsoft Visual Studio.NET 7.0">
<meta name="CODE_LANGUAGE" content="Visual Basic 7.0">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
<script>
function checkGoal()
{
if document.Form1.x1(0).checked
{
document.Form1.1.disabled="true"
document.Form1.2.disabled="true"
document.Form1.3.disabled="true"
}
else
{
document.Form1.1.disabled="false"
document.Form1.2.disabled="false"
document.Form1.3.disabled="false"
}
}
</script>
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<input type="radio" name="x" id="1" > <input type="radio" name="x" id="2">
<input type="radio" name="x1" id="11" onclick="checkGoal();" style="Z-INDEX: 101; LEFT: 56px; WIDTH: 22px; POSITION: absolute; TOP: 88px; HEIGHT: 20px">
<input type="radio" name="x" id="3">  <input type="radio" name="x1" id="21" "checkGoal();" style="Z-INDEX: 102; LEFT: 88px; WIDTH: 18px; POSITION: absolute; TOP: 88px; HEIGHT: 20px">
</form>
</body>
</HTML>
hope this will help you
  Reena Jain replied to anil namburi
25-Feb-11 05:58 AM
hi,

To make a radio button not selectable, in the button's INPUT tag you can use an onClick event handler like this:
<INPUT type="radio" name="myButton" value="theValue"
onClick="this.checked=false;
alert('Sorry, this option is not available!')">

hope this will help you
  Anoop S replied to anil namburi
25-Feb-11 06:17 AM
Refer this code for disabling radio button

<html>
<head>
<title>Enable Disable Radio button  in javascript</title>
</head>
<script>
 function chMd()
 {
  // initialize form with empty field
  
  document.forms[0].goServer.disabled=false;
  
  for(var i=0;i<document.forms[0].elements.length;i++)
  {
  if(document.forms[0].elements[i].name=="dOption")
  {
   if(document.forms[0].elements[i].value=="N")
   {
     if(document.forms[0].elements[i].checked==true){
  
  
    document.forms[0].sRadio[0].disabled=true;
    document.forms[0].sRadio[1].disabled=true;
    document.forms[0].sRadio[2].disabled=true;
  
    document.forms[0].goServer.disabled=true;
     }
   }
   else if(document.forms[0].elements[i].value=="T")
   {
     if(document.forms[0].elements[i].checked==true){
      
  
    document.forms[0].sRadio[0].disabled=true;
    document.forms[0].sRadio[1].disabled=true;
    document.forms[0].sRadio[2].disabled=true;
  
    document.forms[0].goServer.disabled=false;
     }
   }
   else if(document.forms[0].elements[i].value=="R")
   {
     if(document.forms[0].elements[i].checked==true){
    
  
    document.forms[0].sRadio[0].disabled=false;
    document.forms[0].sRadio[1].disabled=false;
    document.forms[0].sRadio[2].disabled=false;
  
    document.forms[0].goServer.disabled=false;
     }
   }
  }
  }
 }
</script>

 
<body>
<form name="fRadio">
  <input name="dOption" value="N" checked="checked" onClick="chMd()" type="radio">
   No Constraints <br />
 
  <input name="dOption" value="T" onClick="chMd()" type="radio"> Text Box
 
 
  <input name="dOption" value="R" onClick="chMd()" type="radio">  Radio Button
  Radio A  <input name="sRadio" value="A" disabled="disabled" type="radio">
  Radio B  <input name="sRadio" value="B" disabled="disabled" type="radio">
  Radio C  <input name="sRadio" value="C" disabled="disabled" type="radio"> <br/>
  <input name="goServer" value="Go" disabled="disabled" type="button">
  </form>
</body>
</html>
  anil namburi replied to Reena Jain
25-Feb-11 08:03 AM
Hi,
Still it is not working.Can u please provide any other alternative solution.According to yor code when ever user clicks on radion button it is disabling but it also un selecting the radio 'YES' selection.I need radio 'YES' should be selected and it should be in a disable state.
Create New Account
help
enable / disable button based on cell value Excel Hello, I have created a toggle button from the Control Toolbox. The function of the button is to hide / unhide columns. What I would like to do is make the button available based on a cell's value. More specifically, what I would like to do is enable the button only if cell A1 has a value that is less than half of the value
Can we disable button in Windows application. Hi, How can we disable button in C# Windows application after the button is clicked once for the first time ? Can anyone help me with this. Thanks in advance. Yes you can disable button , On click of button write button.Enable = false; when user will click button first time , it will disabled by
Enabled / Disable Button Control using javascript Here i will show how you enable or disable any controls which supports disable / enable feature in javascript. Enabled / Disabled Button using Javascript For enable the button, document.getElementById('Button1').disabled = false; For disable the button, document.getElementById('Button1').disabled
how to disable / enable command button (ActiveX) using a macro Excel I have tried to create a macro using recorder to disable / enable command button (ActiveX) with the following code being created ActiveSheet.Shapes("CommandButton1").Select This only results in the command button being selected - with the procedure of enabling / disabling being "lost". So i tried the following 1) Hopes (1) Button1 (1) Naneek (1) you can try this to hide / unhide specific button like"button1" Sub hide_specific_button() ActiveSheet.Shapes("Button 1").Visible = False End Sub Sub unhide_specific_button() ActiveSheet
how to disable / enable command button(ActiveX) using macro Excel I have tried to create a macro using recorder to disable / enable command button (ActiveX) with the following code being created ActiveSheet.Shapes("CommandButton1").Select This only results in the command button being selected - with the procedure of enabling / disabling being "lost". So i tried the following 1) Ezt (1) ActiveSheet.CommandButton1.Enabled = False - - Regards! Stefi ???enahs_naneek??? ezt ??rta: keywords: how, to, disable / enable, command, button(ActiveX), using, macro description: I have tried to create a macro using