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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T10:05:38+00:00 2026-05-20T10:05:38+00:00

i am sure this is quite a numb question to ask and most probably

  • 0

i am sure this is quite a numb question to ask and most probably the most basic one. i am just a starter for JS.

i am trying to access the value of input field by document.getElementById and it is returning null to me i am not sure why here is the code.

<html>
    <head>
        <script type="text/javascript">
            var name = document.getElementById("e_name");
            alert(name);
        </script>
    </head>
    <body>
        <form action="" method="post">
            <input type="text" name="name" id="e_name" value="Enter your Name"/>
            <input type="submit" name="submit"/>
        </form>
    </body>
</html>

the following code prints the value null in alert box. what is wrong?

Update :

When i use the following code.

<html>
    <head>

    </head>
    <body>
        <form action="" method="post">
            <input type="text" name="name" id="name" value="Enter your Name"/>
            <input type="submit" name="submit"/>
        </form>
        <script type="text/javascript">
            var name = document.getElementById('name').value;
            alert(name);
        </script>
    </body>
</html>

it prints Enter your Name but if i change the value it does not print the changed value. i would want to perform the following for validation purpose

a) holds the value of e_name in a javascript variable in the head tag

b) so that i should be able to process it for validation.

how do i do it?

  • 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-20T10:05:38+00:00Added an answer on May 20, 2026 at 10:05 am

    Because you’re calling that line of script even before document object is ready!

    Try this

    <body>
            <form action="" method="post">
                <input type="text" name="name" id="e_name" value="Enter your Name"/>
                <input type="submit" name="submit"/>
            </form>
    
            <script type="text/javascript">
                var name = document.getElementById("e_name").value;
                alert(name);
            </script>
    
    </body>
    

    Or this in your head tag.

        <script type="text/javascript">
            window.onload = function() {
                var name = document.getElementById("e_name");
                alert(name);
            }
        </script>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Not quite sure how to word this question. I am wondering if there is
I'm quite sure this is a stupid question, but all my tries failed. I
First off, an apology as I am sure this is question's answer is quite
I am quite sure this question has already been asked several times and I
I'm quite sure this a simple issue, but I am trying to create a
I'm sure this has to be one of the most common things done in
I'm very new to threading and thus am not quite sure if this even
Wasn't quite sure how to word this but let's say I've used ssh to
I'm not quite sure how to approach this issue: I am creating a web
I'm not quite sure how to do this. Let's say I have 2 associative

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.