-1

I have created a textbox using JavaScript

var textInput = document.createElement("input");

Now I want to get text from that textfield in JavaScript.

How can I get it?

i have tried with defining Input.id = 'inp' and var get = document.querySelector("#inp").value; but cant get solution.

Hamza Awan
  • 99
  • 1
  • 3
  • 9
  • Did you try something already? – omri_saadon Nov 02 '18 at 20:13
  • yes i have tried with defining **Input.id = 'inp'** and **var get = document.querySelector("#inp").value;** but cant get solution. – Hamza Awan Nov 02 '18 at 20:14
  • Possible duplicate of [How do I get the value of text input field using JavaScript?](https://stackoverflow.com/questions/11563638/how-do-i-get-the-value-of-text-input-field-using-javascript) –  Nov 02 '18 at 20:14
  • 1
    @HamzaAwan Why don't you show us what you tried? –  Nov 02 '18 at 20:14
  • 1
    Welcome to SO. You might find reading the site [help section](https://stackoverflow.com/help) useful when it comes to [asking a good question](https://stackoverflow.com/help/how-to-ask). To get the best answers to your question we like to see a) that you've attempted to solve the problem yourself first, and b) used a [mcve] to narrow down the problem. Asking SO to do all the work for you doesn't help you or us. [Here's a question checklist you might find useful.](https://meta.stackoveXXxrflow.com/questions/260648/stack-overflow-question-checklist). – Andy Nov 02 '18 at 20:16
  • can anyone help me? – Hamza Awan Nov 02 '18 at 20:23
  • @HamzaAwan We need a [mcve]. It's not possible to help you based on the limited information we have. –  Nov 02 '18 at 20:32

1 Answers1

0

You're missing one key piece in creating HTML elements with JS. The code you have creates the element, but it's not actually being placed into the document.

document.body.appendChild(textInput);

This will actually insert the created element into the body. You then should be able to access it's contents.

Jared Bledsoe
  • 559
  • 5
  • 15