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

  • Home
  • SEARCH
  • 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 301927
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T07:03:03+00:00 2026-05-12T07:03:03+00:00

I have a form which posts data to the same page. Based on the

  • 0

I have a form which posts data to the same page. Based on the user’s radio button selection I am inserting checked=”checked” into the radio button form element to redisplay the correct selection. This works fine, however when the form is redisplayed (in case of bad input etc), I need a div to be revealed (containing the relevant fields from the form).

I have an onclick event that reveals the div in the first place (before the user has posted the form), and this works fine, but when I redisplay the form I don’t want the user to have to manually reveal the form again by clicking.

Therefore I’ve been trying something along the following lines (heavily cut down for the purposes of this post)…

<link href="styles/style1.css" rel="stylesheet" type="text/css" />
 <script language="JavaScript"> 
  if (document.getElementById('complete_yes').checked) {
   document.getElementById('repair_complete').style.display = 'block';
   } else {
     document.getElementById('repair_complete').style.display = 'none';
  }
 </script>
 <form action="javascript_test.php" method="POST">
  <input id="complete_yes" type="radio" name="complete" checked="checked" value="true"/>Yes
  <input id="complete_no" type="radio" name="complete" value="false"/>No
  <input type="submit" value="Save">
   <div id="repair_complete">
    I'm a div!
   </div>

… but it returns an Object Required javascript error (as it does in the ‘real’ page):

Message: Object required
Line: 3
Char: 1
Code: 0
URI: http://localhost/repair_system/javascript_test.php

Why is this? Am I not correctly referencing the form element? Apologies if I’m being a “div” (deliberate bad pun intended!), I’m yet to learn about the fun and games of javascript!

  • 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-12T07:03:03+00:00Added an answer on May 12, 2026 at 7:03 am

    Because your javascript is not wrapped inside a function, the browser is executing it as soon as it “gets to it”. In this case, the JS is being executed before the browser has reached the html declaring your form.

    The simplest fix therefore is to move the Javascript to after your form. A more robust solution would be to wrap you code in a function, and have that triggered somehow – from what you appear to be trying to do, in this case it’ll be the onLoad event of the body tag:

    <head>
    <script language="JavaScript"> 
      function showHelpDiv() {  
        if (document.getElementById('complete_yes').checked) {
         document.getElementById('repair_complete').style.display = 'block';
        } else {
         document.getElementById('repair_complete').style.display = 'none';
        }
      }
    </script>
    </head>
    <body onload="showHelpDiv()">
     <form action="javascript_test.php" method="POST">
      <input id="complete_yes" type="radio" name="complete" checked="checked" value="true"/>Yes
      <input id="complete_no" type="radio" name="complete" value="false"/>No
      <input type="submit" value="Save">
       <div id="repair_complete">
        I'm a div!
       </div>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

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

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

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

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

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Try the clientWidth property, like so: $('body').attr('clientWidth') From the Mozilla… May 12, 2026 at 6:05 pm
  • Editorial Team
    Editorial Team added an answer Try this, works for me. createCookie("city", '%e6%b8%a9%e5%b7%9e%e5%b8%82'); //do not decode… May 12, 2026 at 6:05 pm
  • Editorial Team
    Editorial Team added an answer class Door(models.Model): bar = models.CharField(max_length=123) class Caravan(models.Model): foo = models.CharField(max_length=123)… May 12, 2026 at 6:05 pm

Related Questions

I am still mostly unfamiliar with Inversion of Control (although I am learning about
When the form is submitted, I'm calling a function getPosts and passing through a
I'm converting an old classic asp website to asp.net. The application is basically an
This question is mainly geared towards Zend in PHP, although it certainly applies to

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.