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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T00:00:56+00:00 2026-06-18T00:00:56+00:00

We have a webform and here is how the radio code is set up

  • 0

We have a webform and here is how the radio code is set up in this php form:

<input type="radio" name="2074" id="2074" value="Yes" class="valuetext" >Yes
<input type="radio" name="2074" id="2074" value="No" class="valuetext" >No

I’m working on some custom validation code that is fine for the text fields, but just hit a snag with radio buttons, so I’m sure this will be an issues for check-boxes

so here is the code that validates,

function blank(field) {
    if ((field.type == "text" || field.type == "textarea") && (field.value == " " || field.value == ""))
    {
        return true;
    }
    else if ((field.type ="radio" || field.type == "checkbox") && (!(field.checked || field.selected || field.selectedIndex > -1)))
    {
        return true;
    }
    else {
        return false;
    }
}

but when it comes to the radio buttons, it only checks the first radio button it runs into. so for example, if I run the validation and neither radio in the set is checked, it works, gives me the error message i needed, but that is only because it checked the first button, which was empty.

if I select “no“, the second option of the radio, it does not work correctly, show me an error message when it should not

if I select “Yes” the first option of the radio, it works as expected.

How do I get JavaScript to grab all the radios in the group, check if any in that group are checked ?

Thank you in advance.

Function that gathers fields that need to be examined:
*Also, that is a json script above this that provides the data for fieldlist*

var field = [], blankFields = [],
        listText = [], listItem = [], fieldId = [], label = [];

function checkRequired(fieldList) {
    for (var i = 0; i < fieldList.length; i++)
    {
        listText = fieldList[i];
        listText = listText.substring(1, listText.length - 1);
        listItem = listText.split("||");
        fieldId = listItem[0];
        label = listItem[1];
        field = document.getElementById(fieldId);

        if (visible(field) && blank(field)){
            blankFields.push(label);
        }
    }
    //return blankFields;
    if (blankFields.length > 0) {
        displayError(blankFields);
    }
}
  • 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-18T00:00:57+00:00Added an answer on June 18, 2026 at 12:00 am

    I decided to mix in some jquery which made life tons easier:

    else if (field.type=="radio")
                    {
                     var radiocheck = $('input[type="radio"][name="' + field.name + '"]:checked').size() > 0;
                     if (radiocheck == false){
                         return true;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a php web form, when user selects a radio button, I want
I have a webform with a custom calidator function. in the form is a
I have a php webform that uses an external js file that external files
I have a weird issue that is probably simple here is the code js
P.S. I am new to php & webform scripting; Currently I have the following
I have the following HTML generated by Drupal <fieldset id=webform-component-lunchset class=webform-component-fieldset form-wrapper style=> <div
Here is the situation: I have a webform that needs to read specific fields
I'm puzzled here. I have a webform with 3 tables in it. I want
I have a webform-based macroeconomics model here that takes parameters and inputs and solves
I have a button on my webform. Clicking this button will do an HttpWebRequest

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.