On 30/03/2006 22:52, Ouch! wrote:
The script works on IE and Mozilla but fails on Safari on the MacOSX.
Care to be more specific? Those of us that can't test code on that
platform directly can't help you without a detailed error description.
[snip]
var reOKFiles = /^([a-zA-Z].*|[1-9].*)\.(doc|DOC|pdf|PDF|rtf|RTF)$/;
var filenamePattern = /^[a-z1-9].*\.(doc|pdf|rtf)$/i;
is much simpler, and would accept other, more usual (though valid)
capitalised forms of the extension.
//where i check for the file...
if(window.document.myForm.myDocument.value != ""){
var fileStr = window.document.myForm.myDocument.value;
if(!reOKFiles.test(fileStr)){
alert("Please try again, you tried to upload an invalid file type
for CRITERIA 1");
window.document.myForm.myDocument.focus();
return (false);
I would write this as:
var uploadDocument = document.forms.myForm.elements.myDocument;
if (uploadDocument.value
&& !filenamePattern.test(uploadDocument.value)) {
alert('You tried to upload an invalid file type for'
+ ' Criteria 1.\nPlease try again.');
if (uploadDocument.focus) {uploadDocument.focus();}
return false;
}
though the reference to the form control could be reduced under certain
conditions. For example, by passing a reference to the form element
(presumably this code is part of a function called from the submit event
listener) and storing a reference to the elements collection if multiple
elements are being validated simultaneously.
It probably wouldn't make much of a difference, but feature testing the
focus method isn't a bad idea.
Please follow-up by repeating the error message you receive, and what
might be triggering the error. Finally, don't use tabs when posting to
newsgroups; use spaces to indent (preferably never more than four per
level).
Mike
--
Michael Winter
Prefix subject with [News] before replying by e-mail.