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 7730129
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T06:08:45+00:00 2026-06-01T06:08:45+00:00

Declaration: I am not sure if that is a parameter. Please enlighten. I have

  • 0

Declaration: I am not sure if that is a parameter. Please enlighten.

I have a medical questionnaire form with almost 19 yes and no radio buttons.Each question’s radio buttons must have a unique input name in order to make it work. I manage to find a suitable code to toggle an text area if the yes radio button is selected however, it can only work in one of the input name and there are 18 more which needs it to be working as well.

My main question is:

function displayTextBox()
    {
        var objElement = document.getElementById('addmed');
        addmed.style.display = 'block';
        addmed.style.visibility = 'visible';
    }

    function hideTextBox()
    {
        var objElement = document.getElementById('addmed');
        addmed.style.display = 'none';
        addmed.style.visibility = 'hidden';
    }

    function validate()
    {
        var arrElements = document.getElementsByName('medq');
        var objElement;
        var boolContinue = false;
        var objaddmedtext;

        for(var i=0, _length=arrElements.length; i<_length; i++)
        {
            objElement = arrElements[i];

            if(objElement.checked)
            {
                if(objElement.id == 'yes')
                {
                    objaddmedtext = document.getElementById('addmedtext');

                    if(strTrim(objaddmedtext.value).length>0)
                    {
                        boolContinue = true;
                        break;
                    }
                }
                else
                {
                    boolContinue = true;
                    break;
                }
            }
        }

        if(boolContinue)
        {
            alert('Continue, user completed the information.')
        }
        else
        {
            alert('Ask user to complete the data.')
        }
    }

    /**
     * Removes all white space characters from the string.
     * 
     * @param: {String} String to trim.
     * 
     * @return {String} Trimed string.
    */
    function strTrim(strTrim) 
    {
        return strTrim.replace(/^\s+|\s+$/g, '');
    }

Looking at this javascript,a textarea

<div id="addmed" style="display:none;visibility:hidden; margin-left:10px; width:110px;">
        <textarea id="addmedtext" cols="60" rows="6" placeholder="Please give details with dates"></textarea>
</div> 

will only appear if the yes radio button is selected for

<tr>
<td width="33">1.</td>
<td width="491">Heart or circulatory problems including: high blood pressure, heart attack, angina, heart murmur, heart failure, palpitations, circulatory problemseg. whitefinger, blocked arteries, stroke aneurysm.</td>
<td width="68"><input name="medq" id="yes" type="radio" value="yes" onclick="displayTextBox()"/><label for="yes"> Yes </label></td>
<td width="78"><input name="medq" id="no" type="radio" value="no" onclick="hideTextBox()"/><label for="no"> No </label></td>

However, this is only 1 question…I have 18 more question with name="medq 1 to 18 ".

Any ideas how to edit the javascript to add the parameters??

  • 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-06-01T06:08:47+00:00Added an answer on June 1, 2026 at 6:08 am

    First, you need to have unique ID on every radio button. But you need the same NAME on each pair of YES/NO button to process the selected one of the pair. So you can have

    <input type="radio" name="foo" id="foo_y" value="yes" /><label for="foo_y">Yes</label>
    <input type="radio" name="foo" id="foo_n" value="no" /><label for="foo_y">Yes</label>
    <textarea id="foo_text" name="foo_text"><textarea>
    

    Now, for the “yes” radio buttons, you can add onclick=”displayTextBox( this )”. “this” is a pointer to the current radio button.

    You can then update the function like so:

    function displayTextBox( f ) { // f is the field that was clicked
        f.style.display = 'block';
        f.style.visibility = 'visible';
    }

    Now it’s a generic function. Do the same for the “hide” function.

    Finally, you can update your validate function to loop over the array of form input fields instead of looking at the one field.

    1. var arrElements = document.getElementsByTagName("input");.
    2. Inside your loop: if( (objElement.type === "radio") && (objElement.checked) ) {.
    3. Don’t use if(objElement.id == 'yes'), check for the value of the current field: if(objElement.value == 'yes')
    4. Finally, you can grab the text from the related textarea: objTextArea = document.getElementByName( objElement.name + "_text" );

    So, you’re just making each of the existing functions generic and looking for the meta data of each field, rather than trying to code for each field.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am sure that I am not the first to encounter this conflict. The
If I have a form-backing object that has a complicated object tree -- say
A using declaration does not seem to work with an enum type: class Sample{
I am wondering why the second map declaration (using the diamond operator) does not
// I prefer to perform forward declaration on myclass, as I do not //
As discussed here , C# doesn't support generic attribute declaration. So, I'm not allowed
I have an application that is used in image processing, and I find myself
I have a base class that declares and defines a constructor, but for some
I've got a RegularExpressionValidator (ASP.NET 2.0) that I'm using to make sure that a
I came across the declaration in a software best practices guide that algorithm and

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.