Click here to Skip to main content
15,896,329 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to set focus on control i clicked but my code not working
Here is my code
JavaScript
else if (answer is HandwrittenAnswer)
{
  this.Sourcecode.AppendLine("\t\t\t\t<textarea id='" + id + "' name='" + id + "' value='' style='position: absolute; "
                                                         + "top: " + top + "px; left: " + left + "px; height: " + height + "px; width: " + width + "px; "
                                                         + "visibility: hidden; z-index: 2; resize: none;'></textarea>");
  this.Sourcecode.AppendLine("\t\t\t\tdocument.getElementById id='" + id+ "' .focus();");
}

with above code when i click on my web form it goes inside the control i click but there is no focus set it means when i click text box is opened and when i write something nothing happens because there is no focus so i need to click one more time then can write something but i want to set focus directly when i click on my control.
Anyone got idear whats wrong ?????Solution
Posted
Updated 12-Jan-15 23:43pm
v3
Comments
Kornfeld Eliyahu Peter 13-Jan-15 5:35am    
Your second line (getElementById) is wrong syntactically!
Member 11000455 13-Jan-15 5:41am    
how to correct it???well i am new with javascript so got no idea
Sibasisjena 13-Jan-15 5:49am    
You have to write code like below:
document.getElementById("yourControlId").focus();

1 solution

Please have a look on the below links:
JavaScript set focus to HTML form element[^]
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900