/    Sign up×
Community /Pin to ProfileBookmark

Java Focus() not working

Hi ! I have used focus() function but the control dose not stay in the same textbox. Below is the code .

[CODE]
if (flag == 0) {
alert (“You must be from 20 intervention school”);
document.getElementByName (“username”).focus();
return false;
}

[/CODE]

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@tirnaJun 30.2010 — is "username" an element id or name.

If it is a name and given more than one element can share the same name then your code might not work because the browser won't know which element of the same name to focus on.

But if only one element exists with that name then try

[CODE]
document.getElement[COLOR=red]s[/COLOR]ByName ("username").focus();
[/CODE]


But I would tend to give the element an id and use getElementById() instead....but that's just me...?
×

Success!

Help @arpit_vavadia spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.28,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...