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

  • Home
  • SEARCH
  • 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 8214933
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T11:37:12+00:00 2026-06-07T11:37:12+00:00

I am new to javascript. I am doing a feedback form where there are

  • 0

I am new to javascript. I am doing a feedback form where there are 12 radio buttons that need to get validated individually and a textarea will be displayed when I click a particular value.

Here, when I click that button, my textarea, which is in display, should be mandatory entered (eg: when I click fail option in a results question, then I should mention in which subject he failed through that textarea. something like that).

For this, I have written code, it’s working fine with the 1st radio button, but unable to call this recursively for remaining buttons.

I need to call this code in a function recursively, but my variables need to get change everytime. Like for 2nd time, I should use option2,text2, likewise in next call option3,text3, etc.

var option = $("#form1 input[@name=radio1]:checked").val();
var text = document.getElementById("text1").value;

if (!$("#form1 input[@name=radio1]:checked").val()) {
    alert("Please fill all the fields");
    return false;
    errs++;
} else if (option == "3" && trim(text) == "") {
    alert("Please enter comments.");

    return false;

}

This piece of code needs to be called for var option1 to option10 and same text1 to text10. Like:

var option2 = $("#form1 input[@name=radio2]:checked").val();
var text2 = document.getElementById("text2").value;

This should get called immediately of completion of first radio button.

Please help me out.

  • 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-07T11:37:15+00:00Added an answer on June 7, 2026 at 11:37 am

    “Recursive” is the wrong word here. You just want to loop over all the elements.

    Get all the radios, and loop over them. Then get the ID, and all the fields associated with that id.

    I’m assuming you’re using jQuery, so here’s an example:

    // Note: The "@" is not needed in jQuery
    var radios = $("#form1 input[name^='radio']"); // "^=" means "starts with"
    radios.each(function(){
        var id = this.name.replace('radio', ''); // this will get the number, eg: 1
        var option = $(this).val();  // get radio's value
        var text = $('#text'+id).val();  // get textX's value
    
        if(!$(this).is(':checked')){ // check if radio is checked
            alert("Please fill all the fields");
            errs++;  // make sure to do this before "return false"
            return false;  // break the .each loop
        }
        else if (option == "3" && trim(text) == "") {
            alert("Please enter comments.");
            return false;
        }
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I`m new to JavaScript and I need some help extracting the ID from URL
im new at javascript and i can get this slider to work but not
New to JavaScript, and what I'm doing below seems right from all the Google
I've been doing some reading about two (relatively) new concepts in the Javascript language
I'm new to javascript, my problem is effectively: I have a php page that
I am still new to Javascript. I need to attach a function to handle
I'm relatively new javascript, but I am comfortable in other languages. I'm trying to
I'm using Nodejs and Socket.io. When the client connects, new JavaScript objects are created.
New to javascript and such, trying to create a loop for fading logos using
New to javascript, but I'm sure this is easy. Unfortunately, most of the google

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.