Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Check existence or form objects

Status
Not open for further replies.
Sep 27, 2001
179
AU
I am writing some custom code for an application that allows javascript extenstions. All the code does is to check a passport expiry date.

The app displays two screens; a read only summary screen and then a edit screen.

On the summary screen the field is hidden and has the name
"_HIDDENpers_passport" but on the edit screen it has the "name pers_passport".

So I have written the following code which works on the Summary screen but not on the Edit screen due to the different names of the forms objects. The application uses the same piece of code for both screens, and there is no way round this.

Code:
<script language="javascript">
window.onload = function pd()
{
var pd =document.all._HIDDENpers_passport.value;
if (new Date(pd) < new Date()){
alert ("Passport Expired!");
}
}</script>

Is there anyway to check the existence of the objects? Or perhaps supress the errors and write extra code to accomodate both states?

Thanks

Rob
 
Sorted it thanks with the following :D

Code:
<script language="javascript">
window.onload = function pd()
{


if (document.all._HIDDENpers_passport) {
var pd =document.all._HIDDENpers_passport.value;
if (new Date(pd) < new Date()){
alert ("Passport Expired!");
}}
else
{
var pd =document.all.pers_passport.value;
if (new Date(pd) < new Date()){
alert ("Passport Expired!");
}
}
}</script>

Rob
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top