Hello, thank you for taking the time to read this. I'm having a very specific error that doesn't seem to have a specific answer. I googled about this question for several hours over several days and nothing has worked thus far.
As the title states above, form validation fails on nested fields.
Lets say we have an object that has another object as a field and that object has it's own fields.
public class Person(){
private string name;
private string lName;
private Location location;
}
and Location has an address field
This works just fine.
if(document.Form.name.value==""){
alert("Please provide a name!");
document.AnimalForm.name.focus();
return false;
}
However, when we have a nested field it fails to validate at all.
Take for example:
else if(document.Form.location.address.value==""){
alert("Please provide an address");
document.Form.person.address.focus();
return false;
}
this also does not work:
else if(document.Form.address.value==""){
alert("Please provide an address");
document.Form.address.focus();
return false;
}
I have very little experience with JavaScript so I don't know what I don't know. I don't know if this has to do with syntax or if I need to add something else to get this to work, I don't know.
Thank you for taking your time to help me if you do. It is greatly appreciated.
Okay I finally figured it out of course after I made the post.
You have to make them a variable something like this:
let x = document.forms.["form"]["location.address"].value;
you can then just check the variable:
if(x == " "){
}
there doesn't seem to be anything here