+ 6
How I can create a input with JS ?
How I can create a input with JS .Example I create a input,after a client type a input in it and he click on a submit and at the end Client's input turns to other input that I want.Example in phuysical quantities such as Celcius in Kelvin.
8 Answers
+ 10
use prompt()
Ex: user=prompt (" enter somting" )
+ 7
<input type="text" oninput="txt=this.value">
<input type="button" value="Submit" onclick="changeInput()">
<script type="text/javascript">
var txt;
function changeInput(){
alert("User input: "+txt+"\nChange this text however you want...");
}
</script>
+ 3
please answer me,if you've any question or problem please ask from me.
+ 3
Yes I know it , but how I can do it this work with create a input tag with HTML and change it with a submit as I want
+ 3
Because my internet speed is sh*t here, I am not sure if I sent already an answer. But if I didnt, try something like this:
HTML:
<input type='number' id='firstInput' />
<p id="output"></p>
<button onclick='myFunction()'>click</button>
JS:
function myFunction() {
var input = parseInt(document.getElementById("firstInput").value);
var output = document.getElementById("output");
//calculations, here you can insert your own formula
output.innerHTML = (input + 5);
}
+ 3
@ali
parseInt(...) means "transfer a number instead of a string" so if you type 4 it will be an integer, not a string (so parseInt(...)+4 = ...+4, but without parseInt() it would be "..." + 4.
So if (...) is 5, in the first case it would be 5+4=9, in the second it would be '5'+4=54).
For the second one, to be honest, I am not sure.
+ 2
Thank you "Ice" your massage was sent to me.I've 2 question :
What is the "parseInt(...)" ?
How I can enter that answer in that input (I dont wanna use from p tag and ...,just I wanna enter the answer in that input.)
+ 2
Thanks