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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T22:04:52+00:00 2026-05-26T22:04:52+00:00

I already saw this question however, it didn’t work for me whatever I tried.

  • 0

I already saw this question however, it didn’t work for me whatever I tried.

My function is:

function validatePreviousChecked(parent, child) {
    found = false;
    element = document.getElementsByName(parent);
    for (i = 0; i < element.length; i++) {
        if (element[i].checked == true) {
            found = true;
        }
    }

    if (!found) {
        alert("Please answer the questions in order. It seems that you didn't answer a previous question");
        document.getElementsByName(child).checked = false;
        return false;
    }
    return true;
}

function disableAll(elements) {
    var myelements = document.getElementsByName(elements);
    for ( var i = 0; i < myelements.length; i++) {
        myelements[i].disabled = true;
    }
    return true;
}

and my radio button:

<input onclick="javascript: if(validatePreviousChecked('q1_financial_product','q1_product_likelihood[0]')){disableAll('q1_product_likelihood');}" value="1" name="q1_product_likelihood" type="radio" />

However, the first function is being executed, returning true (I validated it) but never the second one!

What is wrong?

EDITED

This is another snippet:

<input
                    value="1" name="q1_financial_product"
                    onclick="disableAll
        ('q1_financial_product')"
                    type="radio" />
  • 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-26T22:04:52+00:00Added an answer on May 26, 2026 at 10:04 pm

    There’s a lot wrong with the code. Don’t mean to bash it but here are some suggestions. The first is what I think is the cause of the problem, the others are just to improve your code.

    • You’re passing "q1_product_likelihood[0]" as the child argument to validatePreviousChecked which is used to call document.getElementsByName("q1_product_likelihood[0]"). That doesn’t make sense, the name of a control should not be q1_product_likelihood[0]. If there are multiple and you want the first one, you need to pass an additional index parameter that can be used to call document.getElementsByName(child)[index].
    • Your i variable in the loop for validatePreviousChecked is global, as is found.
    • Your onclick handler starts with javascript: That’s not wrong per se, since JS treats it as a label, but it’s not doing what you think it’s doing, remove that.
    • Instead of calling JS from the HTML, you should be setting handlers from the onload/domready handler, then you would have a regular, more readable function as the handler which you could debug, inline code is much harder to debug.
    • Why does disableAll return true? Doesn’t do any harm but adds bloat to the code and may make someone think that it means something.

    How did you validate that it’s returning true? If it’s returning true, it’s impossible that disableAll is not being called. You should prove that you validated it by specifying where you added log statements and what the output was.

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

Sidebar

Related Questions

I saw this post on SO already but it still begs the question, at
Note: I already saw this and it doesn't answer the question. I have a
I already saw an answer here , but it didn't really answer my question.
I saw a post on this already, but it didn't really provide a solution
I saw this question already on this forum but I do not know why
I already know the obvious answer to this question: just download <insert favorite windows
I already asked this question at the JOS-.NET board but Joel is closing that
Before you mark this as answered in another post (I already saw those). But
I'm asking this question because it isn't the first time I saw this coding
I saw this question : XPathDocument vs. XmlDocument But it doesnt have the info

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.