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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T17:56:16+00:00 2026-05-11T17:56:16+00:00

Ok, this situation is a little weird but anyway. This PHP code generates several

  • 0

Ok, this situation is a little weird but anyway. This PHP code generates several radiobuttons:

    for($i = 0; $i<count($questionList); $i++)
    {
        echo $questionList[$i]->__get(QuestionId).'-'.$questionList[$i]->__get(QuestionText).'<br />';

        $answerList = $questionList[$i]->GetAnswers();

        for($j = 0; $j<count($answerList); $j++)
        {
            echo '<br /><input type=\'radio\' name=\'group'.$i.'\' id=\'radioButtonAnswer'.$answerList[$j]->__get(AnswerId).'\' value=\''.$answerList[$j]->__get(AnswerId).'\' >'.
            $answerList[$j]->__get(AnswerText).'</input>';
        }
        echo '<br /><br />';
    }

Ok, that works fine, after the checkboxes are created, I’m trying to run some code to get all the radio buttons and it didn’t work, so I tried just getting one radio button several times, and it only gets it the first time.

function Validate()
{

    var i = 1;

    do
    {
        document.writeln(document.getElementById('radioButtonAnswer2') == null);

        i ++;
    }while(i < 10);

    document.writeln('out of loop');

    return false;
}

So I know FOR SURE that ‘radioButtonAnswer2’ exists and it shouldn’t be null. But this is what I get when I click the submit button:

false true true true true true true true true out of loop

The first time is not null, but after that, it is. Any thoughts?

Thanks!

  • 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-11T17:56:17+00:00Added an answer on May 11, 2026 at 5:56 pm

    It may be because your HTML you are generating is invalid. You also shouldn’t be explicitly calling the __get() function, but that’s an unrelated issue most likely.

    Something like:

    <input type="radio" ...>Label Text</input>
    

    is not the correct way to define a radio button.

    Try this code:

    for($j = 0; $j<count($answerList); $j++)
    {
            echo '<br /><input type="radio" name="group'.$i.'" id="radioButtonAnswer'.$answerList[$j]->AnswerId.'" value="'.$answerList[$j]->AnswerId.'" />';
            echo '<label for="radioButtonAnswer'.$answerList[$j]->AnswerId.'">'.$answerList[$j]->AnswerText.'</label>';
    }
    

    Edited to add: Ah, now I see. You’re using document.writeln(). That function overwrites the content of the page.

    So the first time into the loop, the element does exist, and it does a document.writeln() call, which writes “true” to the page. This overwrites everything that was on the page before (didn’t you notice how when the page loads, it only has the output of the javascript?). The next time through the loop, it tries to look for the radio button again, but it’s been erased and replaced with the javascript output. Now it no longer exists.

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

Sidebar

Related Questions

i know this could be a little weird but a doubt is a doubt
I've been struggling with this error for several days with little headway. Basically, I'm
I noticed this situation in my code (unfortunately), and was able to duplicate it
I'm not entirely sure how I got to this situation but somehow I'm getting
I'm a little confuse with nhibernate and cache management. I have this situation. We
Ok, this is a little weird. Ignore what I am trying to do, and
Blocks are fine but what about writing C arrays? Given this simplified situation: CGPoint
I'm running into a weird situation with a PHP execution of a SQL query
This might be a little subjective, but I'd like to get your input on
Edit: fixed several syntax and consistency issues to make the code a little more

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.