1

I have a data validation program that I made in Javascript and it works fine, it basically shows extra information for a particular date such as, what day it was on, and other info.

My problem is I dont know how to put into the HTML tag.

Here is also a screenshot of my task: enter image description here

var canvas;
canvas = openGraphics();
var day;
day=prompt( "Please enter your day of birth");
var month;
month = prompt( "Please enter your month of birth");
var year;
year = prompt( "Please enter your year of birth");
var date;
date = new Date( year, month-1,day);
if(true){
if(date.getFullYear()== year )
{   
}
if( date.getMonth()== month-1 )
{               
}
if( date.getDate()== day )
{
}
else{
alert( "Invalid Date" );
}
}
canvas.setFont( "Palatino Linotype", "24px", Font.PLAIN );
canvas.setColor("blue"); 
canvas.drawString( "Full DOB:", 10, 10 );
canvas.drawString( date, 100, 10 );
canvas.paint();

My attempted HTML so far, the is all wrong and I need someone to show me how to implement my code above into a html format:

<html>
<head>
<title>
Date Validation
</title>
<script>
function checkdate(){

var year = document.getElementById('year').value;
var month = document.getElementById('month').value;
var day = document.getElementById('day').value;

var date = new Date( year, month-1,day);

if(true)

{

if(date.getFullYear()== year )
if( date.getMonth()== month-1 )               
if( date.getDate()== day )

}

else{
alert( "Invalid Date" );
}
</script>
<body>
<h1>Data Validation</h1>
<p> This page will be used to provide information on the specific date that  you    enter below. </p>
<form>
Day:
<input type = "text" input id="day" onchange = "checkdate();>
</form>
<form>
Month:
<input type = "text" input id="month" onchange = "checkdate();>
</form>
<form>
Year:
<input type = "text" input id="year" onchange = "checkdate();">
</form>
<form>
<input type="submit" value="Validate Date">
</form>
</body>
</html>

1 Answer 1

1

You need to close the quotes, and remove input from the middle of your lines. Instead of

<form>
Day:
<input type = "text" input id="day" onchange = "checkdate();>
</form>
<form>
Month:
<input type = "text" input id="month" onchange = "checkdate();>
</form>
<form>
Year:
<input type = "text" input id="year" onchange = "checkdate();">
</form>

Use

<form>
Day:
<input type="text" id="day" onchange="checkdate()">
</form>
<form>
Month:
<input type="text" id="month" onchange="checkdate()">
</form>
<form>
Year:
<input type="text" id="year" onchange="checkdate()">
</form>

Also, it's a good habit to avoid using semicolons like onchange="checkdate();"

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.