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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T23:33:45+00:00 2026-05-30T23:33:45+00:00

A call to getElementById() to retrieve a ‘hidden’ field on a form is returning

  • 0

A call to getElementById() to retrieve a ‘hidden’ field on a form is returning null.

I’ve studied other SO questions and many were using the hidden field’s ‘name’ instead of ‘id’ in the call to getElementById() or were executing getElementById() in a script at top-of-file before the actual html containing the hidden field had been processed by the browser. Both of those errors would explain why getElementById() was returning null for them.

I could be wrong but I don’t think that’s my case here.

This is my form:

  <form name="theDeleteItemForm" id="deleteItemForm" action="deleteTheSelectedItem" 
             method="post"
    <input type="hidden" id="theHiddenField" name="deleteThisSelectedItem" value="">
 </form> 

And here is a Javscript handler that is successfully executing when a ‘delete’ button on the page is clicked (I can tell because my alert() boxes in the handler function below are popping up):

function deleteItem()
{
    alert("Just entered deleteItem()");

    var theFieldToDelete = document.getElementById('theHiddenField');

     // THIS IS THE PLACE WHERE I FOUND THAT 'theFieldToDelete' WAS 'null'
    alert("Just got the hidden field element, which is: " +  theFieldToDelete );

      // THIS DOES NOTHING MORE THAN TO PREVENT THE 'alert' THAT FOLLOWS FROM APPEARING
    theFieldToDelete.value = "upForDeletion";

    alert("deleteItem() was called, about to submit the form");

    document.theDeleteItemForm.submit();    
}

I’m not understanding why I get the null return from getElementById(). I’m under the impression that
getElementById() works FINE for type="hidden" fields.

Furthermore, the id I used for my hidden field — theHiddenField — is 100% unique in my file.

Why am I getting null when I try to get the hidden field via getElementById() ?

  • 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-30T23:33:47+00:00Added an answer on May 30, 2026 at 11:33 pm

    Probably it’s because your <form> element isn’t formed properly (as in quoted example – the > is missing in the opening tag)?

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

Sidebar

Related Questions

How to call javascript onmouseout event in javascript code? I.e.: var div=document.getElementById('new'); if(div.mouseout) document.getElementById('new').style.visibility='hidden';
I call a javascript function from a textbox by using OnKeyPress=clickSearchButton() Here is my
<script language=javascript> function toggle(id) { alert('call'); if (document.getElementById(id).style.display == none) { alert('now visible'); document.getElementById(id).style.display
I have an application that needs to retrieve a value out of a hidden
I'm using an XMLHttpRequest to retrieve XML from the server, and I'd like to
I am using the jQuery autocomplete plugin and have wired up an input field
I am using a java applet to call Web Services. This java applet is
I am using an Ajax call to a PHP file to get data from
I've got this onclick call: onClick=mySubmit(); which calls this function: function mySubmit(){ document.getElementById(myForm).submit(); }
I'm trying to call a function within an object literal that I created, using

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.