I've always been wondering this, but all websites seem to be answering the opposite (how to make text typed in an input be the input of a function). Is there a way to do it?
Asked
Active
Viewed 49 times
-6
-
1give us an example of a code, a scenario etc. and what you have tried.. – Mostafa Talebi Sep 20 '15 at 05:24
-
1`someInput.value = aFunction();` ... I doubt you [couldn't find any information](https://www.google.com/search?q=javascript+set+text+input&ie=utf-8&oe=utf-8) in the entire Web about setting values of form inputs fields. – Felix Kling Sep 20 '15 at 05:25
1 Answers
1
Is this what you want to do?
function myFunction() {
// some functionality here
// this function must return something
}
var input = document.querySelector('input');
input.value = myFunction();
This will set the value of the input
element to the value returned by myFunction
.

Arnelle Balane
- 5,437
- 1
- 26
- 32