How can I go get a year in a text box made in HTML with javascript?

  • Thread starter Thread starter Silent
  • Start date Start date
S

Silent

Guest
Well, the main problem is that none of your code does anything like what the assignment specifies.

Your CAge1() function creates a date object referencing the current date, then a number object containing the value of that date's year. It does nothing with these values and returns.

Your CAge2() function throws up an alert box with a message referencing a local variable you defined in another function, which of course doesn't work.

I'm assuming this is some kind of homework assignment. If so, I think you need to go back and review your textbook (or whatever) because teaching you how JavaScript works is a little beyond the scope of this question.
 
Ok, here's the deal:
I have a text-box in HTML called "Date" where you enter your birthday like this ==> February 15th 1992. In JavaScript, I have to do a code where I can calculate the age with the same text-box "Date". How don't know how to do it! I tried this but it doesn't work:

function CAge1()

{

var dteNow = new Date();
var intYear = dteNow.getFullYear();

}

function CAge2()

{

alert("You have " + intYear);

}

Where is the problem???
 
Well, the main problem is that none of your code does anything like what the assignment specifies.

Your CAge1() function creates a date object referencing the current date, then a number object containing the value of that date's year. It does nothing with these values and returns.

Your CAge2() function throws up an alert box with a message referencing a local variable you defined in another function, which of course doesn't work.

I'm assuming this is some kind of homework assignment. If so, I think you need to go back and review your textbook (or whatever) because teaching you how JavaScript works is a little beyond the scope of this question.
 
Back
Top