Click to See Complete Forum and Search --> : focus() on field when link is clicked


cmotor
09-06-2003, 05:09 PM
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>')
}

Charles
09-06-2003, 06:19 PM
You can't, really. Not unless you play some ugly games with frames. Try instead...

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}

And call it thusly:

<form action="" onsubmit="return checkForm(this)">