0

This is kind of unusual, but is there anyway to add text into JavaScript via the input tag?

For instance,

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

and let's say the JavaScript is

function show_alert()
{
alert("The text entered in #example will show up here");
}

Is this anyway possible?

1 Answer 1

2

In straight Javascript (i.e. no libraries), you can use:

var exampleValue = document.getElementById('example').value;

Working example: http://jsfiddle.net/nrabinowitz/H6bKL/

But if you're going to do much of this, and especially if you want to get values from a variety of form elements, you'd do yourself a favor using jQuery or another library with good DOM access functions.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.