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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T06:28:14+00:00 2026-06-13T06:28:14+00:00

I have been struggling for a while to get javascript to validate a WordPress

  • 0

I have been struggling for a while to get javascript to validate a WordPress based HTML form which uses radio buttons. I finally came up with a solution with was a bit long-winded but worked – at least in IE and Chrome – however, it doesn’t work in Firefox (which suggests my code is a bit sloppy). I think my radio button reference is the issue. Can anyone help with what I have done wrong – apart from use an inefficient approach for validation :-)?

A simplified version of my form:

<script>
function validateForm()
{
var aa=document.forms["personalise"]["motivation"]["1a"];
var ab=document.forms["personalise"]["motivation"]["1b"];
var ac=document.forms["personalise"]["motivation"]["1c"];
var ad=document.forms["personalise"]["motivation"]["1d"];
var ae=document.forms["personalise"]["motivation"]["1e"];
if (!(aa.checked == true || ab.checked == true || ac.checked == true || ad.checked == true || ae.checked == true))
 {
  alert("Question 1 must be completed");
  return false;
 }
}
</script>
<form name="personalise" action="insertdatatest.php" onsubmit="return validateForm()" method="post">
1. Are you seriously planning to quit </b>:&nbsp;&nbsp;
    <input id="1a" type="Radio" title="" name="motivation" value="1" />  Within the next 2 weeks
    <input id="1b" type="Radio" title="" name="motivation" value="2" />  Within the next 30 days
    <input id="1c" type="Radio" title="" name="motivation" value="3" />  Within the next 3 months
    <input id="1d" type="Radio" title="" name="motivation" value="4" />  No, I am not currently planning to quit
    <input id="1e" type="Radio" title="" name="motivation" value="5" />  I have already quit
<input type="submit" value = "Submit">
</form>

I am a real newbie at web development, so any help would be much appreciated.

  • 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-13T06:28:16+00:00Added an answer on June 13, 2026 at 6:28 am

    Thanks again TheDeadMedic for your help. Actually I found a slightly different way of doing it which worked in all three browsers which was set up for multiple radio button questions (hence the blOK entries). In case it is useful to any others, the code is below. Flix.

    <script>
    function validateForm() { 
    var inputs;
    var i;
    var blOK;
     blOK = false;
     inputs = document.getElementsByName( "motivation" ); 
     for (i=0;i<inputs.length;i++)
     {
       if ( inputs[i].checked   ) {
                                    blOK = true ;
            break ;           
                                    }
    }
            if (!blOK) 
            {
    alert( "Question 1 must be completed" ); 
    return false;  
            }
    </script>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Have been struggling with Javascript closure for a while trying to wrap brain around
Have been struggling with this for a while, and can never seem to get
I have been struggling with this for a while now. given a set of
I have been struggling with encoding problems in MySQL for a while. I am
I've been struggling with this issue for a while now. I have OpenCart 1.5.2.1
I've been struggling with this for a while. Basically, I want to have two
I have been struggling with setting up an iOS (Objective-C) app which utilizes the
I have been struggling all afternoon trying to get a simple mailto: tag to
I have been puzzling with this for quite a while and can't get it
I have been struggling a while with this problem and read a lot but

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.