/    Sign up×
Community /Pin to ProfileBookmark

Hi, I have an exam on Javascript tomorrow and I am looking at past exams papers.

Can you please help me out of this?
I know I am asking you this as if I let it all in your own hands. But I really don’t know how to do it!!

This is part of multiple questions. Can you just tell me how to write the code for a simple page, starting at the new function writing (see below).

->At present, if the user clicks the “Calculate Name” button without entering
any names, the output will default to the first name in the midName array.
Write a new function called checkNames() that displays an alert to the user
if they do not enter any names. You will also need to specify where in the
code you would place a call to this function.

to post a comment
JavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@AdamBrillJan 14.2003 — Try something like this:

function checkNames()

{

if(document.formname.inputname.value=="")

{

alert("Please enter your name");

}

}

Will that work?
Copy linkTweet thisAlerts:
@hitmanauthorJan 14.2003 — i tried it, it doesn't work. do i need to put something else? it just gives me a blank page.
Copy linkTweet thisAlerts:
@AdamBrillJan 15.2003 — Yeah, that was just the function. Try the following code:
<i>
</i>&lt;html&gt;
&lt;head&gt;
&lt;script language=javascript&gt;
function checkNames()
{
if(document.form1.T1.value=="")
{
alert("Please enter your name");
return false;
}
return true;
}
&lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;form method="POST" onsubmit="return checkNames()" name=form1&gt;
&lt;input type="text" name="T1" size="20"&gt;
&lt;input type="submit"&gt;
&lt;/form&gt;
&lt;/body&gt;
&lt;/html&gt;

That will check if the textbox name T1 is empty. If it is, it popups up the alert, and if it isn't it submits the form. Let me know if it still doesn't do what you want...
Copy linkTweet thisAlerts:
@hitmanauthorJan 15.2003 — thanks. it is what i wanted.
×

Success!

Help @hitman 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 6.16,
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: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

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