furtivevole
Technical User
In an HTML form, there is a potential field whose existance depends on a previous user action. Before submitting the form, I have to check that the field both exists and is suitably populated. The client-side code for this is:
//Code A
var strNameX=document.FrontPage_Form1.Name;
if(eval(strNameX+"==null")) {
alert ("Wrong (Code A)");
return false;
}
//Code B
var strNameVal=document.FrontPage_Form1.Name.value;
if (strNameVal.length==0) {
alert ("Wrong (Code B)");
return false;
}
else {
alert ("Successful");
return true;
}
If the field does not exist, then code A executes correctly and the function returns false. However if the field does exist - whether or not populated - Code B executes only if code A is commented out.
I guess I've missed something subtle here - can anyone advise please?
//Code A
var strNameX=document.FrontPage_Form1.Name;
if(eval(strNameX+"==null")) {
alert ("Wrong (Code A)");
return false;
}
//Code B
var strNameVal=document.FrontPage_Form1.Name.value;
if (strNameVal.length==0) {
alert ("Wrong (Code B)");
return false;
}
else {
alert ("Successful");
return true;
}
If the field does not exist, then code A executes correctly and the function returns false. However if the field does exist - whether or not populated - Code B executes only if code A is commented out.
I guess I've missed something subtle here - can anyone advise please?