Forum : Please help with this question
Brief description  about Online courses   join in Online courses
View Sasmita  Patnaik 's Profile

Please help with this question

Write a JavaScript Webpage that reads in the date of a day in one textbox, the month in a second and the year in a third. At the push of a button then a text area should report the complete date, including placing the correct extension on the day number. ('st', 'nd', 'rd' or 'th'). Example : 2 April 1999 will produce: 'Today is the 2nd of April, 1999.'
Asked by Sasmita Patnaik | Jul 30, 2010 |  Reply now
Replies (1)
View teacher siliconindia 's Profile
Hi Sasmita,

Please go through the below javascript code,

function Module3()
{
vdate = document.myform.field1.value;
vmonth = document.myform.field2.value;
vyear = document.myform.field3.value;
v = "";

if( (vdate == "") || (vmonth == "") || (vyear == ""))
{
alert("Please don't enter null values");
return false;
}
else {

if(vdate>0 && vdate<=31)
{
if( (vdate == 1) || (vdate == 21) || (vdate == 31) )
{
v = "st";
}
else if( (vdate == 2) || (vdate == 22) )
{
v = "nd";
}
else if( (vdate == 3) || (vdate == 23) )
{
v = "rd";
}
else
{
v = "th";
}
}
else
{
alert("Please enter date in the range 0-31");
return false;
}

if(vmonth!='january' && vmonth!='february' && vmonth!='march' && vmonth!='april' && vmonth!='may' && vmonth!='june' && vmonth!='july' && vmonth!='august' && vmonth!='september' && vmonth!='october' && vmonth!='november' && vmonth!='december')
{
alert("Please enter a valid month name");
return false;
}

if(!Number(vyear) || vyear.length!=4)
{
alert("Please enter a valid year");
return false;
}

alert("Welcome... Today Is: ' "+vdate+""+v+" of "+vmonth+", "+vyear+". '");

}

return true;
}

Regards,
Vishwanath M S

Aug 3, 2010