This is a basic JavaScript form-validation I created. All the document.form.*.value references are present on my page, except for the document.form.dasdasdas.value ==''.
In the code below, the purpose is to display an error if any of the forms are left empty. However, since dasdasdas is not a valid form on my page, no error occurs. My question is why.
If it doesn't exist, shouldn't it be considered empty?
I noticed that even after filling in all the fields (customername to customerpostcode) and leaving customerbank and customercity empty, it still indicates that everything is okay.
Upon removing that line, everything functions properly. But I am intrigued by why it behaves this way!
Your response to this somewhat murky explanation would be much appreciated!
Here is the code I am referring to:
function FileChecked()
{
if( document.form.customername.value =='' ||
document.form.customerpassword.value =='' ||
document.form.customerphone.value =='' ||
document.form.customeremail.value =='' ||
document.form.customeradres.value =='' ||
document.form.customerpostcode.value =='' ||
document.form.dasdasdas.value =='' ||
document.form.customerbank.value =='' ||
document.form.customercity.value =='')
{
alert('Not all forms are filled.');
return false;
}
// Check if file is selected and has a .csv extension
if(document.form.csvfile.value =='')
{
alert('No file given');
return false;
}
else
{
ext = document.form.csvfile.value.toLowerCase();
if(ext.substr(ext.length-4) == '.csv')
{
return true;
}
else
{
alert ('Filetype is not .csv');
return false;
}
}
}