Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JS - Dynamically change Textfield

I'm trying to change the value in one textfield from the value of another textfield without any submits. Example:

[Textfield 1 (type 'hello')]

[Textfield 2 ('hello' is inserted here as well)]

Below is my form:

<form action="#" id="form_field">
   <input type="text" id="textfield1" value="">
   <input type="text" id="textfield2" value="">
</form>

I don't know much about JavaScript, is this even possible? Would appreciate any help.

Thanks

like image 756
Oliver Jones Avatar asked Feb 21 '23 19:02

Oliver Jones


1 Answers

<form action="#" id="form_field">
   <input type="text" id="textfield1" value="" onKeyUp="document.getElementById('textfield2').value=this.value">
   <input type="text" id="textfield2" value="">
</form>

see it in action: http://jsfiddle.net/4PAKE/

like image 175
micha Avatar answered Feb 27 '23 10:02

micha