View Full Version : select() in a form - javascript

10-17-2007, 04:11 PM
Hi. I have written the following text which works totally except for one thing. If the email input box has been typed into, after the message "Please enter a valid email address"l, I want that text written in error to be highlighted so the client doesn´t have to delete it and can just type straight back in with a corrected email address.

function email_onblur()
var email = document.form1.email.value;
var atSign = email.indexOf("@")
if ((atSign == -1) == true)
alert("Please enter a valid email address.");


I feel it is the text highlighted in green above that is not working, everything else is ok. Any ideas?

Many thanks.

10-17-2007, 04:49 PM


refers to the proper element, then after focusing on it:


will select it. However, you may have the wrong element, or no element.

In an effort to eliminate those possibilities, try:

function email_onblur(){
var e = document.form1.email;
var atSign = e.value.indexOf("@")
if (atSign < 0){
alert("Please enter a valid email address.");

Also, the use of an alert my be overriding the focus() and/or select() directives - or just be changing the focus and selection of the document after those directives. Remember, you have to click on an alert to close it.

If you need more help:

Please post a link to the page on your site that contains the problematic script so we can check it out.