...

View Full Version : validation help



finstah1
06-21-2004, 03:08 PM
I am using this script to validate a field called "field"

<SCRIPT LANGUAGE="JavaScript">

<!-- Begin
function verify() {
if (document.fileupload.first.value=="") {
alert("Please attach a file to upload");
return false;
}
}
// End -->
</script>

However, when I use a name like this for the field "wcsave_a9-photofile" as
document.fileupload.wcsave_a9-photofile.value==""

it will not validate. Is there any reason for this?

thanks in advance

homerUK
06-21-2004, 03:24 PM
the JS could think that the "-" in the name is a minus and might be trying to do a calculation?

that's all I can think of at the mo!

finstah1
06-21-2004, 03:43 PM
I replaced the "-" with a "_" and it seems to work fine. Thanks for the help :)

homerUK
06-21-2004, 03:48 PM
happy to help :D glad you got it sorted! :thumbsup:

glenngv
06-22-2004, 03:47 AM
Another way of accessing field is the "elements" collection using the bracket notation (http://www.litotes.demon.co.uk/js_info/sq_brackets.html). This is specially helpful if the name of the field has special characters that are illegal when accessed using the dot notation, as in this case.

if (document.fileupload.elements["wcsave_a9-photofile"].value=="") ...



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum