/    Sign up×
Community /Pin to ProfileBookmark

focus() on field when link is clicked

I am using the code below to validate a form.

I need code to have the cursor focus on the applicable form field when the history.go()-1 link is clicked.

I did a search but could not find the information I was looking for.

Thank you in advance

-cmotor

CODE:
function checkform() {

if (isEmpty(document.Returnform.customer_name.value)) {
document.write(‘<html>ERROR: The field for your FIRST AND LAST NAME was left blank. All form fields must be completed in order to process your return. <a href=”javascript:history.go(-1);”>Click here to go back and fix it.</a></html>’)
}

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@CharlesSep 06.2003 — [font=geprgia]You can't, really. Not unless you play some ugly games with frames. Try instead...

[font=monospace]function checkForm (f) {if (!/S/.test(f.customer_name.value)) {alert ('ERROR: The field for your FIRST AND LAST NAME was left blank. All form fields must be completed in order to process your return.'); f.customer_name.focus(); return false}[/font]

And call it thusly:

[font=monospace]<form action="" onsubmit="return checkForm(this)">[/font][/font]
×

Success!

Help @cmotor 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 6.14,
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: @meenaratha,
tipped: article
amount: 1000 SATS,

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

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