Ok this may be a stupid questions. Is there a way to make a dynamic form? For example, if I wanted to create a form that took a users birthday, how do I make it so it would change the number of days in the month to correspond to the month selected. (with out having to submit the form). So if a user was to select their birth month as February it would put the number of days to 28. Any Ideas?

Thanx in advance

~Atrus

javascript obviously.

Javascript has a little quirk where a date of zero will set the date to be the last day of the previous month. Likewise is there are 30 days in a month and you set a date of 31 it will be the 1st day of the next month, a date of 40 would be the 10th day of the next month. This can lead to some very weird funkiness if you're not careful but we can definitely exploit this for a useful prototype which will give us the number of days in a specific month. We'll do this up as a prototype so it's available to all our Dates.

Date.prototype.daysInMonth = function () {
   return new Date(this.getFullYear(), this.getMonth()+1, 0).getDate()
}

var d = new Date();
document.writeln('Number of days in this month: '+d.daysInMonth());

This came from here:

http://www.hunlock.com/blogs/Javascript_Dates-The_Complete_Reference

All you need to do is substitute this.getMonth() in the prototype with document.getElementById("usermonthdropdown").value

Member Avatar for fatihpiristine

nice topic

javascript obviously.

Is there anyway of doing it w/o java?

~Atrus

>Is there anyway of doing it w/o java?
We *are* doing it without java! Javascript is *NOT* Java tsk.

I cannot think of any better solution than using javascript. You have to execute SOMETHING on the client if you don't want to postback server-side to do it. To do that you need to run a program. The options are:

Javascript (By far the most common sense solution)
Java Applet (overkill)
VBScript (IE browsers Only)
ActiveX Control (IE Only and overkill)

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.