locked
Radio Button Linked to Text Box RRS feed

  • Question

  •  I want to link a radio button to a text box so that when the radio button is checked you can enter data into the text box.  When the radio button is unchecked the information in the text box goes away.  Can I do this using the Tag properties task pane or by using behaviors?  I am not much on coding and prefer using the task panes. Thanks.
    ROC
    Monday, February 16, 2009 7:44 PM

Answers

All replies

  •  Just curious:  Why do you want to do that?
    Monday, February 16, 2009 7:49 PM
  • This is a pretty standard configuration.  Here is a link with the box I am working on.

    http://www.strategicresourceinc.com/Survey2/ExitInterviewSurvey.html
    ROC
    • Edited by rocrocroc Monday, February 16, 2009 8:10 PM correction
    Monday, February 16, 2009 8:04 PM
  • For effects like that I use jQuery.  In fact I use jQuery for all my JS work now.  Its dead simple with jQuery to get th effect you want.
    --
    Chris Hanscom - Microsoft MVP
    Resource Center | Veign's Blog | Web Development Help
    Monday, February 16, 2009 8:28 PM
  • Sample code coming in a few minutes - working on it now.
    --
    Chris Hanscom - Microsoft MVP
    Resource Center | Veign's Blog | Web Development Help
    Monday, February 16, 2009 8:42 PM
  • Here's sample code doing what you want:
    http://www.veign.com/preview/jquery

    Just view the source.

    --
    Chris Hanscom - Microsoft MVP
    Resource Center | Veign's Blog | Web Development Help
    • Proposed as answer by Veign Monday, February 16, 2009 8:55 PM
    • Unproposed as answer by rocrocroc Tuesday, February 17, 2009 3:41 PM
    • Proposed as answer by Veign Tuesday, February 17, 2009 4:31 PM
    • Marked as answer by rocrocroc Friday, February 20, 2009 10:48 PM
    Monday, February 16, 2009 8:54 PM
  • Chris,

    Thank you for your response.  Although I haven't yet tried it as a resolution to my problem, it looks like it may work.  What I am interested in as well is if that can be done using the Task Panes.   Is that possible?
    ROC
    Tuesday, February 17, 2009 3:43 PM
  • Not sure as I use a jQuery for all my JS work.  It gives me the best possible foundation for any JS code.
    --
    Chris Hanscom - Microsoft MVP
    Resource Center | Veign's Blog | Web Development Help
    Tuesday, February 17, 2009 4:31 PM
  • rocrocroc said:

    Chris,

    Thank you for your response.  Although I haven't yet tried it as a resolution to my problem, it looks like it may work.  What I am interested in as well is if that can be done using the Task Panes.   Is that possible?


    ROC

    I could be mistaken, but I don't think so. You're wanting interaction between two different controls (having the state of one control toggle the state of another). Looking at the tag properties exposed by an ASP.NET text control, all of the "enabling" properties (e.g. enabled, visible, read only, etc.) are simple Booleans (true/false). I don't see any way to set/clear them based upon the state of another control using the task pane alone.

    Anyway, this is really among the simplest and most common of possible programming control structures, an if/then statement. If you want to use ASP.NET controls, sooner or later you should consider learning some fundamental programming practices. This wouldn't be a bad place to start.

    cheers,
    scott

    Tuesday, February 17, 2009 5:49 PM
  • Chris,

    That is my next step.  However, on the short term I want to make this html form work in the best way possible.   I have read through Jquery and will learn that as well.  In the questions I have asked so far, I have found there is often a solution using the "mechanical" aspects of EW(2) as well as coding.  Although these solutions are sometimes overlooked, they often represent the best way to do the job.  In this case, your explanation was right to the point and it looks like I will have to code the button :-)  Thanks for your input.
    ROC
    Tuesday, February 17, 2009 7:06 PM
  • All you need to do is view the source of the page I provided and copy the code.
    --
    Chris Hanscom - Microsoft MVP
    Resource Center | Veign's Blog | Web Development Help
    Tuesday, February 17, 2009 7:56 PM
  • Sigh... I suppose that I am subject to mistaken identity today. Twice in less than two hours...   ;-)

    cheers,
    scott
    Tuesday, February 17, 2009 7:56 PM
  • Scott,
     
    Oops, sorry.  I'll not forget your response though.  It was an excellent effort and I appreciate it.
    ROC
    Tuesday, February 17, 2009 9:39 PM
  • Chris,

    I inserted the code into a test website and the code worked as you described.  Unfortunately I could not get it to work in conjunction with my other "radio" buttons.  In my test case I used an existing form.  I have several radio buttons linked by the same name with a different value - a4,1; a4,2; a4,3; a4,4 - they are not included in a group box.  I changed your checkbox to radio and changed the name to a4 with a different assigned value 5.  The result is that I get a change in the checkbox to a radio button that works in conjunction with the other radio buttons but not the textbox.  The texbox will accept input but will not delete that input when the radio button is not checked.  Can you offer a suggestion on how to make it work?  Thanks.
    ROC
    Wednesday, February 18, 2009 4:32 AM
  • Explain exactly how your radio buttons are linked to the textbox and what is supposed to happen and I will update the sample.
    --
    Chris Hanscom - Microsoft MVP
    Resource Center | Veign's Blog | Web Development Help
    Wednesday, February 18, 2009 4:11 PM
  • ROC, just as a suggestion, it helps a lot for questions such as this to explain your objectives and then ask your question(s). Use a format such as this:

    1. What I would like to display in the browser - Be explicit and thorough; include any display elements that bear on your question.

    2. What I would like my visitors to do with my application - Describe the kind of interaction you expect from your visitors.

    3. What I wish to happen when my visitor interacts with my application - What is the purpose of the interaction? Will a new page load, a data view update, a form be submitted, etc.?

    4. What I have done so far and how the expected results vary from what I wish to accomplish - This is the meat of the question, of course, but without the foregoing information in will exist in a vacuum.

    This provides a context for your respondents to work with when trying to address your issue. Not only will it help to zero in on your specific issue, it will provide information that will enable respondents to suggest alternative, perhaps simpler, approaches to achieving your objective.

    cheers,
    scott
    Wednesday, February 18, 2009 5:33 PM
  • Chris, 

    Below is what the radio buttons look like.  Radio Button (RB) 1 is named a4, value 1; RB 2 is named a4, value 2; RB 3, is named a4, value 3; RB 4 is named a4, value 4.  The textbox is named a4a.  The numbers are there just for explanation.  The form name is "test".  The button are not in a group box but can be put in one if necessary. The goal is to activate the textbox when Other is checked and deactivate and clear the text box when Other is not checked.  If it would be easier, link Retire, Other and the text box and I can add the other buttons.  Thanks :-)

       Other Employment (1)
        Moved (2)
        Retired (3)
       Other (please specify) (4)
      Textbox
    e; click next to
    ROC
    Wednesday, February 18, 2009 7:06 PM
  • The sample has been updated with what I think you want.  Let me know if it works for you.
    --
    Chris Hanscom - Microsoft MVP
    Resource Center | Veign's Blog | Web Development Help
    • Proposed as answer by Veign Wednesday, February 18, 2009 9:56 PM
    Wednesday, February 18, 2009 7:46 PM
  • Chris,

    I am just not having any success with this.  Even if I copy your code into a blank page and publish it I have no success.  I have included below a published page taken from your code.  I think I'll take a bit of time to study JQuery and see where I am going wrong.  Thanks for your help.  I appreciate it.

    http://www.strategicresourceinc.com/testpage.html
    ROC
    Thursday, February 19, 2009 2:44 AM
  • You need to download and include the jQuery library.

    See this line of code:
    <script type="text/javascript" src="jquery.js"></script>


    Just go to the jQuery website and download the mini version of the library and rename it to jquery.js and place it in the same folder as your test page.  Basically the framework needs to be included to be able to use it.

    Did the effect I create work as you had wanted it to?

    --
    Chris Hanscom - Microsoft MVP
    Resource Center | Veign's Blog | Web Development Help
    Thursday, February 19, 2009 3:03 PM
  • Chris,

    This is my best effort so far.  I am afraid it will only work with one question so it will require more work.  Question 8.  Thanks for all your help.

    http://www.strategicresourceinc.com/Survey2/test2.html
    ROC
    Thursday, February 19, 2009 4:23 PM
  • Did you get your original sample working by adding the jQuery library?  I have given you the code and now its up to you to use it - gone as far as I can go.  Your latest sample doesn't even include any of the code I gave you.  Just use my sample code as its pretty simple to follow.

    --
    Chris Hanscom - Microsoft MVP
    Resource Center | Veign's Blog | Web Development Help
    Thursday, February 19, 2009 5:15 PM
  • Chris,

    I tried it but was not aware that I had to download the library.  I went in to take the JQuery tutorial just before I read this update and saw that I had to have the library downloaded to my website before it would work.  I'll go back now and give it another try.  I appreciate your help.  I've learned a lot and it looks like others have learned as well.  A good example to keep on hand.  It is such a standard form option you would think EW2 would include it on their options list.  Thanks.
    ROC
    Friday, February 20, 2009 3:28 AM
  • If I were you I would search some of the jQuery samples around as a whole new world will open up to you by knowing jQuery.  Its a great JS foundation to work with.

    Good luck.
    (can you mark my answers as answered since they did do what you needed it)

    --
    Chris Hanscom - Microsoft MVP
    Resource Center | Veign's Blog | Web Development Help
    Friday, February 20, 2009 2:30 PM
  • Chris,

    Thanks for your help. My problem in working with your solution was my failure to download the JQuery script.  For those like me who have no experience with this, the jscript is found on their website and is copied into the file where you have your file.  It looks like it then imbeds itself into the file.  No problem.  Because I have more than one question using this technique on my form, I had to add additional code for each question.  I have included here your sample with the additional questions added.  Thanks.

    http://www.strategicresourceinc.com/test.html
    ROC
    Saturday, February 21, 2009 4:30 AM
  • Good job, glad its all working for you now.
    --
    Chris Hanscom - Microsoft MVP
    Resource Center | Veign's Blog | Web Development Help
    Saturday, February 21, 2009 2:40 PM