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

Ask A Question

Stats

  • Questions 119k
  • Answers 119k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer you shouldnt reinitialize your table with a new JTable after… May 11, 2026 at 11:50 pm
  • Editorial Team
    Editorial Team added an answer one option is to play with different window styles, starting… May 11, 2026 at 11:50 pm
  • Editorial Team
    Editorial Team added an answer The series of events here is supposed to work as… May 11, 2026 at 11:50 pm

Related Questions

Ok, this is a curly one. I'm working on some Delphi code that I
I have created a multi plattform project, and everything works nicely, except one little
Ok, have a bunch of questions that I have been thinking about the past
OK, so I've got this totally rare an unique scenario of a load balanced

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.