I want to get a sentence as input from text field in html and place that sentence as the value for another text field.
Asked
Active
Viewed 262 times
-2
-
Hi and Welcome to SO. please take the tour first. Then read [how to ask questions here](https://stackoverflow.com/help/how-to-ask). After that edit the question to meet the guidelines and provide a [minimal reproducible example](https://stackoverflow.com/help/minimal-reproducible-example) for debugging details. Pictures with code-lines are inacceptable!! – Kunal Tanwar Aug 15 '21 at 05:31
-
1does this answer your question? https://stackoverflow.com/questions/11563638/how-do-i-get-the-value-of-text-input-field-using-javascript – Roohullah Kazmi Aug 15 '21 at 05:38
-
By 'sentence' do you mean the entire contents of an input (i.e. everything the user has typed into that input element)? Or do you require to take everything the user has typed into an input element and extract, say, the first sentence? And/or are you using textarea rather then input? Pleasse provide your code so we can see for ourselves. – A Haworth Aug 15 '21 at 06:38
2 Answers
0
Input fields have a value
property which you can get or set. Assuming your text fields have IDs. You can use grab the value of the first text field and put it in the second one.
let fieldOne = document.getElementById('text-field-one').value;
document.getElementById('text-field-two').value = fieldOne;

waterrmalann
- 1
- 3
-
Yes i did but after that i get only the first word not the whole sentence. Thanks for your concern – Starchild Venus... Aug 16 '21 at 09:37
-
@StarchildVenus... Hmm, that seems weird. Can you edit your question to include the code so that it is more easier to understand what exactly you need? – waterrmalann Aug 16 '21 at 16:13
-1
You can use .value property of input field in JavaScript. But first, you need "find" the input field in DOM. Example: var sent = document.getElementById("input_field").value;
Or you can use this StackOverflow page for example: How do I get the value of text input field using JavaScript?

CatProgrammer
- 14
- 2
-
Whilst this may theoretically answer the question, [it would be preferable](//meta.stackoverflow.com/q/8259) to include the essential parts of the answer here, and provide the link for reference. – mplungjan Aug 15 '21 at 06:16
-
Thank you But if i do like that i get only one word as the value not a sentence – Starchild Venus... Aug 16 '21 at 09:39