2

I'm making a website for my business and in this form I would like for them to choose what's wrong with their device. If their problem is not on the list I would like for them to type it into a <textarea>. I was wondering if I could make that text area one of my radio button options. So far I have this...

<fieldset>
  <legend> What's wrong with your device </legend>

  <label> <input type = "radio" name = "problem">
    					Cracked Screen </label>

  <label> <input type = "radio" name = "problem">
    					Broken Camera </label>

  <label> <input type = "radio" name = "problem">				
    			<textarea rows = "4" cols = "15" name = "problem" 
                         placeholder = "other problems"></textarea>              
                         </label>


</fieldset>

This seems like it would work but I'm worried that it will just render the text area as its own input under the same label. Any advice?

Also I was wondering how to make my radio buttons able to be unclicked. You can only activate them but you cannot deactivate them. Can that only be done with JavaScript?

1

3 Answers 3

2

HTML input is an "empty" element - it does not have an end tag, and cannot contain any children.

You can certainly make it look like your textarea is part of the radio button control, as you did, but it will not behave like it without some Javascript.

2nd question: the user does not usually have a way to uncheck a radio button. You can do it programmatically (e.g., from a button click), or have another "none" option for them to click.

Sign up to request clarification or add additional context in comments.

Comments

0

You cannot nest inputs. Probably best to do is add JavaScript that displays an input text field when the other option is chosen.

Comments

0

Nesting elements not possible

Follow this to achieve what you want.

initially hide textarea element. Toggle textarea visibility based on radio button of your choice.

<fieldset> 
    <legend> What's wrong with your device </legend> 
    <label> <input type = "radio" name = "problem"/>Cracked Screen </label>
     <label> <input type = "radio" name = "problem"/>Broken Camera </label>
     <label> <input type = "radio" name = "problem" class="t_txt"/>  </label>   
    <textarea class="p_txt" style="display:none" rows = "4" cols = "15" name = "problem" placeholder = "other problems"></textarea>

</fieldset>

Jquery

$("input:radio.t_txt").click(function(){
$("textarea.p_txt").toggle();
});

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.