[Javascript] Using Javascript Indexof

Alan Easton alan.easton at unn.ac.uk
Sun Nov 9 19:08:30 CST 2003


Hi Everyone,

I am using the following piece of code to ensure a image filename does not
include the "&" character......

<script language="javascript">
function makefile() {
document.form_save.myfile.value = document.form_save.FILE1.value;
}

function isReady(form) { 
mypic = document.form_save.myfile.value;
if(mypic.indexOf('&') == -1){
alert('Your Image Filename contains INVALID characters);
form.FILE1.focus();
return false;
}
}
</script>

On the actual FILE1 form field, I run an OnChange function that copies what
file has been selected(see above makefile() function) into another form
field called "myfile", it is this field that is then queried using Indexof.

Unfortunately, the alert box pops up all the time, no matter what characters
are in the filename.

Has any one any ideas why it would do this or am I not using Indexof
correctly.

Many Thanks for any help,

Alan...



More information about the Javascript mailing list