Tags: aspx, basic, client, client-sdie, enable, net, postback, radiobutton, script, selected, somebody, textbox, words

Basic client-sdie script: Enable a TextBox when a RadioButton is selected

On .Net » .Net Technology

3,436 words with 1 Comments; publish: Sat, 05 Jan 2008 07:52:00 GMT; (100140.63, « »)

I wonder if somebody can tell me how to enable a TextBox when a RadioButton is selected, without a postback. In other words a 'client script'. Toggle the 'Enabled' property between True and False for the TextBox; should be relatively simple (I hope!).

Sorry, but i'd like to ask for a fairly 'cookbook' response, not because i'm lazy, but becasue i think i can learn from the first example, but have never done any client scripts in ASP.Net at all before. So, i need: (1) The script code to insert, (2) where to insert it (in the aspx.vb file or in the HTML view of the .aspx file?) (3) if in the HTML, then where, in other words, within what currently existing tags?

Thanks much.

Tom

All Comments

Leave a comment...

  • 1 Comments
    • Here's a piece of code I used but in my case, I made the textbox appearor disappear when the radiobutton was slected, not enabled/disabled...

      /// <summary>

      /// function to retrieve the value of a radiobuttonlist

      /// </summary>

      /// <returns>

      /// return the value of the radio button that is checked

      /// return an empty string if none are checked, or

      /// there are no radio buttons

      /// </returns>

      /// <remarks>

      /// Revisions:

      /// - n/a

      /// </remarks>

      function getCheckedValue(radioObj)

      {

      var radioObj;

      if(!radioObj)

      {

      return "";

      }

      var radioLength = radioObj.length;

      if(radioLength == undefined)

      {

      if(radioObj.checked)

      {

      return radioObj.value;

      }

      else

      {

      return "no value returned";

      }

      }

      for(var i = 0; i < radioLength; i++)

      {

      if(radioObj[ i ].checked)

      {

      return radioObj[ i ].value;

      }

      }

      return "";

      }

      /// <summary>

      /// function to hide E-mail textbox, Communications textbox and Communications button

      /// </summary>

      /// <returns>

      /// void

      /// </returns>

      /// <remarks>

      /// Revisions:

      /// - n/a

      /// </remarks>

      function HideEmail()

      {

      var rblvalue = getCheckedValue(document.form.rblAcknowledgment);

      if (rblvalue == "3")

      {

      document.form.txtCustomerEmail.style.visibility = 'visible';

      document.form.txtPerson.style.visibility = 'hidden';

      document.form.btnSearchPerson.style.visibility = 'hidden';

      divMessageD.innerText = 'Please enter Customer's e-mail address';

      }

      else if (rblvalue == "4")

      {

      document.form.txtCustomerEmail.style.visibility = 'hidden';

      document.form.txtPerson.style.visibility = 'visible';

      document.form.btnSearchPerson.style.visibility = 'visible';

      divMessageD.innerText = 'Please select a contact';

      }

      else

      {

      document.form.txtCustomerEmail.style.visibility = 'hidden';

      document.form.txtPerson.style.visibility = 'hidden';

      document.form.btnSearchPerson.style.visibility = 'hidden';

      divMessageD.innerText = '';

      }

      }

      #1; Sat, 05 Jan 2008 07:53:00 GMT