/    Sign up×
Community /Pin to ProfileBookmark

Javascript – alert with label (not with AlertBox)

Hy,

I have test page that inputs some information. Example: I enter name an move to Address field, function validates that in Name field is entered only text. If not alert me with textBox.

I now want to alert me with message next to text field, not in textBox so that I don’t need to press OK.

Can anyone have solution?

thanks

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@grunnersNov 12.2009 — The way I've done this is to put an empty div tag where I want the message to appear e.g.

[CODE]<div id="error_output" class="bold_red"></div>[/CODE]

and then in my javascript I output an error array to this:

[CODE]var errors=new Array();

if (address==""){
errors.push("Please fill in address.<br />");
}
if(errors.length)
{
document.getElementById("error_output").innerHTML=errors.join("n") + "<br /><br />";
return false;
}
return true;[/CODE]


Not sure if this is the best way but when I was writing classic ASP this is how I did it. In asp.net a lot of the validation is built into the controls.

Of course you'd have to find a way of validating the input for text only. Try looking up charCode's and finding out what numbers are for a-z, A-Z etc
×

Success!

Help @tmen15 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.17,
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,
)...