By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,636 Members | 1,207 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,636 IT Pros & Developers. It's quick & easy.

how can we implement the date validation by javascript in drop-down box

P: 21
hi sir,

I have following code:

{code}

[HTML]<html>
<body>
Name:<input type="text" name="n1" id="n1">
DOB: <select name="dd"><option value="date">date</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>
<select name="mm"><option value="month">month</option>
<option value="jan">jan</option>
<option value="feb">feb</option>
<option value="mar">mar</option>
</select>
<select name="yyyy"><option value="year">year</option>
<option value="2007">2007</option>
<option value="2008">2008</option>
<option value="2009">2009</option>
</select>

</body>
</html>[/HTML]


I wanna put the validation in date, month and year for passing the message " future date not allowed" when user select the future date,month year respectivily. How can get element value of the dropdown listbox from html page
for comparing the value from curnnt date function through java script in saparet javascript file.

Thank you.
Jul 22 '08 #1
Share this Question
Share on Google+
4 Replies


10K+
P: 13,264
Give the dropdown an Id and use document.getElementByID.
There's a lot of examples all over the internet for this.
Jul 22 '08 #2

P: 21
hi sir,

1.
<html>
2.
<body>
3.
Name:<input type="text" name="n1" id="n1">
4.
DOB: <select name="dd" id="dd"><option value="date">date</option>
5.
<option value="1">1</option>
6.
<option value="2">2</option>
7.
<option value="3">3</option>
8.
</select>
9.
<select name="mm" id="mm"><option value="month">month</option>
10.
<option value="jan">jan</option>
11.
<option value="feb">feb</option>
12.
<option value="mar">mar</option>
13.
</select>
14.
<select name="yyyy" id="yyyy"><option value="year">year</option>
15.
<option value="2007">2007</option>
16.
<option value="2008">2008</option>
17.
<option value="2009">2009</option>
18.
</select>
19.

20.
</body>
21.
</html>


javascript code goes here:
{code}
function date_validation()
{
var userDate=getElementbyId.....//i havn't idea how can get userdate after user selection
var today = new Date();

if (userDate <= today)
{
alert("future date not allowed");
}
else
{
//alert("uture date allowed");
}
}

how can implement this java script code and please help about helpfull code.

thank you.
Jul 22 '08 #3

10K+
P: 13,264
Perhaps a Javascript tutorial is not a bad thing to read at this point?
Jul 22 '08 #4

gits
Expert Mod 5K+
P: 5,343
please read the posting guideline carefully again ... don't post such a code-mess with line-numbers inline text or whatever, use code-tags, try to explain your problem in more detail and the best would be an example for what you want to achieve, don't multipost questions etc. ... you got a warning already and i don't want to ban you right now ... but be aware that further behaviour in such a way will result at least in a temporary ban ... FOLLOW THE GUIDELINES! ... this is the last friendly warning ...

regards
MOD
Jul 22 '08 #5

Post your reply

Sign in to post your reply or Sign up for a free account.