Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

HTML HTML Forms Choosing Options Radio Buttons

My Radio Buttons not switching to the other option but the name value is the same like in the video but it not working

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>Sign Up Form</title>
        <link rel="stylesheet" href="css/normalize.css">
        <link href='http://fonts.googleapis.com/css?family=Nunito:400,300' rel='stylesheet' type='text/css'>
        <link rel="stylesheet" href="css/main.css">
    </head>
    <body>

      <form action="indexhtml" method="post">
      <h1>Sign Up</h1>

     <fieldset>
       <legend><span class="number">1</span>Your basic info</legend>
      <label for="name">Name:</label>
      <input   type="text" id="name" name="user_name">

      <label for="email">Email:</label>
      <input   type="email" id="email" name="user_email">

      <label for="password">Password:</label>
      <input   type="password" id="password" name="user_password">

       <label>Age:</label>
       <input type="radio" id="under_13" value="user_age"><label for="under_13" class="light">Under 13</label><br>

       <input type="radio" id="over_13"  value="user_age"><label for="over_13" class="light">13 or Older</label>



     </fieldset>

     <fieldset>
     <legend><span class="number">1</span>Your Profile</legend>
      <label for="bio">Comment:</label>
      <textarea id="bio"  name="user_bio"> </textarea>


       <label for="job">Job role</label>
       <select id="job"name="name_job">
        <optgroup label="web">
        <option value="web_developer">web developer</option>
        <option value="rails_developer">rails developer</option>
        <option value="frontend_developer">front-end developer</option>
        <option value="php_developer">php developer</option>
        <option value="wordpress_developer">word press developer</option>
        </optgroup>

        <optgroup label="mobile">
        <option value="ios_developer">ios developer</option>
        </optgroup>

       <optgroup label="other">
       <option value="freelancer">freelancer</option>
       <option value="busmiess_owner">php developer</option>
       </optgroup>

      </select>
       </fieldset>

      <button type="submit"> Sign Up</button>


      </form>    

    </body>
</html>

2 Answers

This should fix it:

<input type="radio" id="under_13" name="user_age" value="under_13"> <label for="under_13" class="light">Under 13</label><br>
<input type="radio" id="over_13"  name="user_age" value="over_13"> <label for="over_13" class="light">13 or Older</label>

The input 'id' attribute must match the label 'for' attribute. The 'name' attribute must be the same for each item in a radio group to ensure only one item can be selected. The 'value' attribute is what is submitted as the selected value when the form is submitted.

Hope this helps.

Fernando Gomez
Fernando Gomez
18,527 Points

Amon, the problem is in your value and id. switch those around like this, but also change id to name:

<input type="radio" value="under_13" name="user_age"><label for="under_13" class="light">Under 13</label><br>

<input type="radio" value="over_13"  name="user_age"><label for="over_13" class="light">13 or Older</label>```