-7

I have created two text boxes in my html document and I would like to assign values to them using JavaScript. I have text that I want to output to these two text boxes. How would I do this?

R andom
  • 101
  • 9
Nate
  • 1
  • 4
  • if by "text boxes" you mean `` then you can change the value using the `value` property of the `input` – Jaromanda X Nov 14 '16 at 05:17
  • That is what I have in my HTML document for the textbox, so what part would I change so that it will read the values from my JavaScript? – Nate Nov 14 '16 at 05:18
  • This is something that is very easily researched on the web. You are really expected to have exhausted research efforts before asking questions here – charlietfl Nov 14 '16 at 05:20
  • `read the values from my javascript` - you mean, so javascript can write values to the input, an input wont "read from javascript" – Jaromanda X Nov 14 '16 at 05:20
  • `document.getElementsByName('clue')[0].value = 'your text goes here';` – Jaromanda X Nov 14 '16 at 05:21
  • `document.getElementsByName("clue")[0].value = "some text";` assuming that element is the first to have that name in document. – Andrew Li Nov 14 '16 at 05:21
  • `` `document.getElementById('idOne').value ='Lasan Pyaaz Dhaniya Adrak'` – Redhya Nov 14 '16 at 05:21
  • not exactly the same @AndrewLi :p the correct way to do something is correct, I guess :p – Jaromanda X Nov 14 '16 at 05:23
  • please try to have some research before posting Questions – Chetan Nov 14 '16 at 05:23
  • 3
    @Chetan - if that's how you feel, why answer? :D – Jaromanda X Nov 14 '16 at 05:24
  • @JaromandaX - i understand, but thought of it would demoralize him. So, gave answer, with comment. i know how it feels if someone gave you negative comment. I hope you understand. Answer will boost his confidence of learning things. i hope :) – Chetan Nov 14 '16 at 05:29
  • @Chetan - I get what you're saying – Jaromanda X Nov 14 '16 at 05:29
  • you can simply use `value property` then why did you use javascript `` – Jishnu V S Nov 14 '16 at 05:44
  • 1
    @Chetan I understand you and also jaromanda-x, But as you said, SO is not a place for these entry level basic questions. here we are supposed to do all our research and if we did not find any way, SO would be our last hope. This question is like the the OP did not know anything at all about JavaScript and did not try anything and the first place he looked at was here. This is not right at all... – EhsanT Nov 14 '16 at 05:46
  • @EhsanT - Agreed, will keep in mind before answering these question. Also i feel that, this is spoon feeding, before posting any question, need basic research and effort that seems zero in this case. one Up vote for your comment. – Chetan Nov 14 '16 at 05:51

1 Answers1

0

You can Use value property of input element -

document.getElementById("user").value = "user name";
document.getElementById("email").value = "sample@gmail.com";
<div>
<input type="text" id="user"/>
<br/>
<input type="email" id="email">
</div>
Chetan
  • 944
  • 5
  • 22