Forum : display date(CAn please tell watz wrong with this script)
Brief description  about Online courses   join in Online courses
View vinaykumar B patil 's Profile

display date(CAn please tell watz wrong with this script)

<htnl><head><script>
function number(value){
hunRem = value % 100;
tenRem = value % 10;
if (hunRem - tenRem == 10) {
return "th";
}
switch (tenRem) {
case 1:
return "st";
case 2:
return "nd";
case 3:
return "rd";
default:
return "th";
}
}

function display(){
var day=document.form.day.value;
var mon=document.form.month.value;
var year=document.form.year.value;
if(iscorrect(day)){
if(isperfect(mon)){
if(isgood(year)){
document.write("Today is " day number(day) " of " mon ", " year);
return true;
}}}return false;
alert("not proper");}
function iscorrect(ele1){
var alpha=/[0-9]$/;
if(ele1.value.length==0)
{
alert("enterr day");
ele1.focus();
return false;
}
else if(!ele.value.match(alpha))
{alert("it must be no");
ele1.focus();
return false;
}return true;
}

function isperfect(ele2){
var alpha=/[0-9]$/;if(ele1.value.length==0){
alert("enterr day");ele2.focus();return false;}else if(!ele2.value.match(alpha)){alert("it must be no");
ele2.focus();return false;}return true;
}


function isgood(ele3){
var alpha=/[0-9]$/;if(ele3.value.length==0){
alert("enterr day");ele3.focus();return false;}else if(!ele3.value.match(alpha)){alert("it must be no");
ele1.focus();return false;}return true;
}


</script>
</head><body>
<form name="form" onsubmit='return display()'>
<table>
<tr><td>Enter Date of a day:</td><td><input type="text" name="day"></td></tr>
<tr><td>Enter month:</td><td><input type="text" name="month"></td></tr>
<tr><td>Enter year:</td><td><input type="text" name="year"></td></tr>
<tr><td><input type="submit" value="Submit"></td></tr>
</table>
</form></body></html>
Asked by vinaykumar B patil | Dec 21, 2010 |  Reply now
Replies (1)
View teacher siliconindia 's Profile
Hi Vinay,

Dude why are you making so much complicated, just call one function, wherein get all three text box values, check whether the user entered number for all three boxes.

then, for date field - number should be in range 1-31
month - range 1-12
year - give some range like 1970-2010 and do validation.

this is enough for u... and print in the above format.. for month, u need to do some conditional assignments, for 1 - january like that...

thats it.
Dec 22, 2010