/    Sign up×
Community /Pin to ProfileBookmark

Hello all,

I am new to JavaScript..

I have a ‘year’ field and below that is a ‘month’ drop down box

I want the user to 1st enter the year and then pull the drop down menu. If they try to pull the dropdown menu before they enter the year I want an ‘alert’ to pop up and ask the user to enter the year first.

It will be of great help if you guys can give me some suggestions

Thanking you all in advance

regards,
smitha

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@sovikFeb 14.2007 — For example:

<i>
</i>&lt;HTML&gt;
&lt;HEAD&gt;
&lt;script&gt;
function foo() {
if(document.getElementById('year').value=='') {
alert ('Please type the year first');
document.getElementById('year').focus();
}
}
&lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;

&lt;form name="form1"&gt;
&lt;input type="text" value='' name='year'&gt;
&lt;select name="aaa" onfocus="foo()" onchange="foo()"&gt;
&lt;option&gt;Select something&lt;/option&gt;
&lt;option&gt;a&lt;/option&gt;
&lt;option&gt;b&lt;/option&gt;
&lt;/select&gt;
&lt;/body&gt;
&lt;/html&gt;
×

Success!

Help @smithakumar spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.5,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...