Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6168791
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T22:44:59+00:00 2026-05-23T22:44:59+00:00

I’d like to write a form with a radio button that opens an optional

  • 0

I’d like to write a form with a radio button that opens an optional input text field.

e.g. radio button : Do you have a wife/husband ? If the user says yes input fields dd, mm, and yyyy appear (for wife/husband birthday day, month, and year) and correct values must be written for the form to be submitted (01 plus 12 plus 1978 are accepted but not 1a plus yy plus 1945).

If the user answers no to the question then this field has no reason to appear (no wife/husband means no wife/husband birthday) and the default values of dd, mm, yyyy are transmitted.

I know how to make a div visible with the style property on the onClick event of the radio button but I have no idea of how to make the input fields compulsory for the yes answer and optional for the no answer (actually not visible and the default values are going to be transmitted).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T22:45:00+00:00Added an answer on May 23, 2026 at 10:45 pm

    I’ve found a very simple way to do this.

    My code for those of you interested :

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>Sample</title>
    
    </head>
    <body>
    <script type="text/javascript">
    function aff_div(ladiv) {
      document.getElementById(ladiv).style.display = "inline";
    }
    
    function cach_div(ladiv) {
      document.getElementById(ladiv).style.display = "none";
    }
    
    function affich_conj() {
      if (document.forms.devis.votconj[0].checked == true) {
        aff_div("ssconj");
      }
    
      if (document.forms.devis.votconj[1].checked == true) {
        document.getElementById("jj").value = 0;
        document.getElementById("mm").value = 0;
        document.getElementById("aaaa").value = 0;
        cach_div("ssconj");
      }
    }
    </script>
    
    <form id="devis" name="devis" action="Validation-du-formulaire.php" method="post">
    
      <label>Do you have a wife/husband ?</label>
      <input type="radio" name="votconj" value="yes" onclick="affich_conj();">yes
      <input type="radio" name="votconj" value="no" checked="checked" onclick="affich_conj();">no
    
      <div id="ssconj">
        <p>
          <label>Her/his birthdate :</label>
          <select name="jj" id="jj">
            <option value="0" selected="selected">--</option>
            <option value="01">01</option>
            <option value="02">02</option>
          </select>
          <select name="mm" id="mm">
            <option value="0" selected="selected">--</option>
            <option value="01">01</option>
            <option value="02">02</option>
          </select>
          <select name="aaaa" id="aaaa">
            <option value="0" selected="selected">--</option>
            <option value="1993">1970</option>
            <option value="1992">1969</option>
          </select>
        </p>
      </div>
    
    </form>
    
    <script type="text/javascript">
      cach_div("ssconj");
    </script>
    
    </body>
    </html>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a text area in my form which accepts all possible characters from
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
For some reason, after submitting a string like this Jack’s Spindle from a text
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a reasonable size flat file database of text documents mostly saved in
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
I have some data like this: 1 2 3 4 5 9 2 6
I have a bunch of posts stored in text files formatted in yaml/textile (from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.