[Gllug] javascript question

Mark Preston mark at markpreston.co.uk
Thu Apr 18 06:26:13 UTC 2002


Hi Adrian,
Re:-
Why does Mozilla trap expired credit cards - but Konqueror (and the Evil 
Empire's browser) do not?

if (parseInt(document.ticket_order.card_year.value, 10) ==  2){
                    var right_now = new Date;
                    if (right_now.getMonth() >=                             
parseInt(document.ticket_order.card_month.value, 10)){
                    alert("Sorry, your credit card appears to have expired. 
Please check 
the expiry date.");
                    return false;
                    }
                    }
                    }




This may be something to do with the way different browsers have different 
start dates. The following script shows how to display the current time on a 
web-page. (Only tested for Netscape and Internet Explorer). Notice Netscape 
requires year+1900, whereas Internet Explorer doesn't..

<script LANGUAGE="Javascript">
<!-- 
//To display current date on a web-page
// Array function
function makeArray(len) {
    for (var i = 0; i < len; i++) this[i] = null;
this.length = len;
}

// Array of day names
var dayNames = new makeArray(7);
dayNames[0] = "Sunday";
dayNames[1] = "Monday";
dayNames[2] = "Tuesday";
dayNames[3] = "Wednesday";
dayNames[4] = "Thursday";
dayNames[5] = "Friday";
dayNames[6] = "Saturday";

// Array of month Names
var monthNames = new makeArray(12);
monthNames[0] = "January";
monthNames[1] = "February";
monthNames[2] = "March";
monthNames[3] = "April";
monthNames[4] = "May";
monthNames[5] = "June";
monthNames[6] = "July";
monthNames[7] = "August";
monthNames[8] = "September";
monthNames[9] = "October";
monthNames[10] = "November";
monthNames[11] = "December";

var now = new Date();
var day = now.getDay();
var month = now.getMonth();
var year = now.getYear();
var date = now.getDate();

bName = navigator.appName;
bVer = parseInt(navigator.appVersion);
 if (bName == "Microsoft Internet Explorer"){
document.write(dayNames[day] + ", " + monthNames[month] + " " + date + ", " + 
year + ".");
}
if (bName == "Netscape"){
document.write(dayNames[day] + ", " + monthNames[month] + " " + date + ", " + 
(year+1900) + ".");
}
// -->
</script>
Regards from Mark Preston



-- 
Gllug mailing list  -  Gllug at linux.co.uk
http://list.ftech.net/mailman/listinfo/gllug




More information about the GLLUG mailing list