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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T08:06:31+00:00 2026-06-18T08:06:31+00:00

When the user enters text in the text field and clicks the submit button

  • 0

When the user enters text in the text field and clicks the submit button their text should come up on the screen. Right now nothing shows.

JS Bin: http://jsbin.com/itotub/1/edit

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Untitled Document</title>
<script>
function myOnloadFunc() {
    var inputAnswer = document.getElementById("inputAnswer");
    var userAnswer = inputAnswer.innerHTML;

    var submitButton = document.getElementById("submitButton");

    submitButton.onclick = function() {
        document.write(userAnswer);
    };
}

window.onload = myOnloadFunc;
</script>
</head>

<body>
<input type="text" id="inputAnswer" placeholder="Enter your answer">
<input type="button" id="submitButton" value=">">
</body>
</html>
  • 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-06-18T08:06:32+00:00Added an answer on June 18, 2026 at 8:06 am

    An input element does not have any descendants, so .innerHTML returns an empty string. If you want to get the value, you have to access the .value property (for more info, see the HTMLInputElement documentation on MDN).

    Another problem is that you are trying to get the value before the user actually typed in anything. You don’t want to get the value on page load but when the user clicks the button:

    submitButton.onclick = function() {
        console.log(inputAnswer.value);
        // or alert(inputAnswer.value);
    };
    

    I would refrain from using document.write, even if it is only for testing purposes. At least understand what happens when you call it after the DOM was loaded.

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

Sidebar

Related Questions

i have a text field in Contact screen and the user need to enter
I need to enable a submit button on my form once the user enters
I'm building a form with a single field and a submit button. A user
I want to make a form with a text field where the user enters
I have a jsp form validate.jsp which contains 2 text fields where user enters
I would like to have a text field that a user can enter a
I have a text box , and user enters text on here , I
How would I make a UILabel update as a user enters text in a
Displaying Type here to ... until the user enters text into a TextBox is
When a user enters a date in text box,i've to check ,whether it is

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.