Issue
Here i have txtemailid and txtlogin(read only) what i type in txtemailid before @ text it will directly go to txtlogin text box when i will happen means when i type something in email text box and next click to mouse without entering the user. how can i do this java and i take code in java script it's not working
Thank you
Solution
It is better you use keyboard event to make changes on each time a key is pressed.I am doing using onkeyup
.I prefer document.getElementById()
rather than document.form
because it can accurately retrieve it, every time, without caring about what happens to the document in the meantime.You can use either of the two.
Here is the code:
function myFunction() {
var text1 = document.getElementById("txtEmailId").value;
var result = text1.split("@");
document.getElementById("txtLoginname").value = result[0];
}
<form>
Enter Email: <input type="text" id="txtEmailId" onkeyup="myFunction()" /><br/><br/> Login Name: <input type="text" id="txtLoginname" /><br/><br/>
</form>
Answered By - shubham agrawal