I am stumped on a javascript that is driving me crazy. I would really appreciate any help. The purpose of the website is to get the birthdate and wedding date from the user. Display the age, number of years married and the days of the week that they were born on and married in the text box.

This is what I have so far.

<html>

<head>


<script type="text/javascript">
function getDay(a,b,c)
function showInfo()

{

var msg="", age="", bDay="", wDay="", birthDay="", birthMonth="", birthYear="", wedDay="", wedMonth="", wedYear="", yearsMarried=""

// SAVE FORM DATA TO VARIABLES

birthDay=document.frmDates.birthDay.value
wedDay=document.frmDates.wedDay.value

var bDay=getDay(birthMonth, birthDay, birthYear);
var wDay=getDay(wedMonth, wedDay, wedYear);



<script type="text/javascript">

var d=new Date();
var weekday=new Array(7);
weekday[0]="Sunday";
weekday[1]="Monday";
weekday[2]="Tuesday";
weekday[3]="Wednesday";
weekday[4]="Thursday";
weekday[5]="Friday";
weekday[6]="Saturday";

msg="You were born on a "+birthDay+"\n"+"You are "+age+"years old"+"\n"+"You were married on a "+wedDay+"\n"+"You have been married for "+yearsMarried+"years."
document.frmDates.results.value=msg
}

</script>

</head>

<body bgColor="blue"
//document.write("You were born on a " + weekday[d.getDay()]);
<BODY OnLoad="document.frmDates.birthDay.focus();">

<body onlerror="alert('error in script?')">

<h2 align="center"> Please enter the following information and press submit. </h2>
<p id="err">&nbsp </p>

<form name="frmDates">
<b>Your Birthday MM DD YYYY:    <input type="text" name="birthMonth" style="width:50px";/><input type="text" name="birthDay" style="width:50px";/><input type="text" name="birthYear" style="width:50px";/><br/><br/>
<b>Your Wedding Day MM DD YYYY: <input type="text" name="wedMonth" style="width:50px";/><input type="text" name="wedDay" style="width:50px";/><input type="text" name="wedYear" style="width:50px";/><br/><br/>

<textarea name="results" cols="110" rows="20"
readonly="readonly"></textarea>

<input type="button" value="Submit" onclick="showInfo(getDay(a,b,c))"/>
<input type="reset"  value="Clear form"/>

</form>
</body>
</html>

age, number of years married and the days of the week that they were born on and married

You will probably find it easiest to proceed step-by-step

create three date objects
birth(year,month,day)
wedding(year,month,day)
today

You can now use their getDay() methods and easily do date arithmetic.

You will probably find it easiest to proceed step-by-step

create three date objects
birth(year,month,day)
wedding(year,month,day)
today

You can now use their getDay() methods and easily do date arithmetic.

Thanks for the reply. I did solve the problem.

Member Avatar for rajarajan2017

Almost you get the both dates from the user, calculate whatever you want with seperate functions and concetenated the result in the textArea to display.

Your design taste is looks bad, I suggest you to also concentrate on your designs, nowadays both are important and first impression is by your design. So be cautious on that.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.