Sign up now to view this solution! It's quick, easy, and secure to subscribe. We will return you to this solution, unlocked, when you’re done.
This links in with a couple of other posts here:
I have this code: [embed=snippet 8161981]
This validates a form 'extra1' and 'extra2'. The problem is, these are dynamic, and it is possible that those forms never exist. Or that just 'extra1' exists and 'extra2' doesn't.
Javascript doesn't like this, it tries of course to run the code and if it tries to validate a form which doesn't exist, it falls over.
I am trying to come up with a 'catch' which will only run the code if that particular form exists, and skip it if not.
Is there a good way to do this?
if ((document.extra1.title1.value ==="") || (document.extra1.firstname1.value==="") || (document.extra1.surname1.value==="") || (document.extra1.bags1.value==="") ||(document.extra1.bags1.value > 3) || (IsNumeric(document.extra1.title1.value)) || (IsNumeric(document.extra1.firstname1.value)) || (IsNumeric(document.extra1.surname1.value)) || (!IsNumeric(document.extra1.bags1.value)))
{
document.getElementById("error").innerHTML="You need to fill in all details for Extra Passenger 1. Ensure text and numerals have been used as appropiate. You can have a maximum of three bags per passenger.";
valid = false;
}
else if ((document.extra2.title2.value ==="") || (document.extra2.firstname2.value==="") || (document.extra2.surname2.value==="") ||(document.extra2.bags2.value > 3) || (IsNumeric(document.extra2.title2.value)) || (IsNumeric(document.extra2.firstname2.value)) || (IsNumeric(document.extra2.surname2.value)) || (!IsNumeric(document.extra2.bags2.value)))
{
document.getElementById("error").innerHTML="You need to fill in all details for Extra Passenger 2. Ensure text and numerals have been used as appropiate. You can have a maximum of three bags per passenger.";
valid = false;
}
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12:
Sign up now to view this solution! It's quick, easy, and secure to subscribe. We will return you to this solution, unlocked, when you’re done.
Posted on 2011-05-09 at 05:37:36ID: 36812471
All comments and solutions are available to Premium Service Members only. Sign up to view the solution to this question. Already a member? Log in to view this solution.