How can I take the value of a text and print on the screen

Asked

Viewed 46,299 times

-2

I am trying to print a value that was typed by user from a textfield, for example a name field.

But after I get it, I want to print that name.

  • 5

    Print a value where? Console? Alert? Other input field? Try to better formulate your question. If possible, put part of your code that is in doubt.

  • for imprimir you can use a alert('') or place the value inside an html element (such as a text). You can also print on the console (used for development)

2 answers

3

To get the entered value, you can do as much by javascript as jquery.

Having the input:

<input type="text" id="inputValor" />

Javascript:

document.getElementById('inputValor').value;

Jquery:

$('#inputValor').val()

By both examples you can get the typed text in the input. I leave Jsfiddle with full example to see:

Example Value Input - fiddle

3

Whereas the ID of the textfield element is id1:

HTML:

<input id="id1" type="text"/>

Javascript:

//Obtem o valor do elemento textfield e armazena na variável "valor"
var valor = document.getElementById('id1').value;

//Para imprimir na página
document.write(valor);

//Para imprimir em um elemento específico
document.getElementById('IdDoElementoEspecifico').innerText = valor

//Para imprimir em um Input Text
document.getElementById('IdDoElementoInputText').value = valor;

Browser other questions tagged

You are not signed in. Login or sign up in order to post.