/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] Can this be done with one prompt box?

Hi,

It’s been at least 3 years since I have had to even think about using JavaScript, but something came up in work today that meant I had to start remembering it quick.

I need a part of a script to take a user name (first name and surname), then produce an ‘alert’ that will confirm the details to the user and tell them their username.

So far I have this:

[code]
name = prompt( “Enter your first name:”, “Firstname” );
surname = prompt ( “Enter your surname:”, “Surname” );

var names = new Array(name , surname);

var fname = “First Name: ” + name + “n”;
var sname = “Surname: ” + surname + “n”;
var uname = “Username: ” + names.join(“.”);
//var uname = “Username is: ” ;

alert( “” + fname + sname + uname );
[/code]

(It may not be the best way to set about doing it but I am a network security guy so JavaScript is not something I usually need to use.)

This used to be done by email but my users complained it takes to long to reach them with their user name (apparently either less than a minute is not good enough or they can’t be arsed to open outlook)

There is another script that goes off and does what it needs to do with the username.

I’m just wondering if it is possible to do it from the one prompt() box instead of using two?

It is part of a bigger picture, that uses a very antiquated system; the username format changes very regularly which is why I want to inform the user there and then what their username will be – my guys are getting too many complaints.

Thanks for any help.

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@DokJul 30.2007 — Provided only two words are inputed with at least one space between them
[CODE]var name = prompt("Enter your name and lastname:", "Name and lastname" );
name = name.split(/s+/);
// Firstname is name[0]
// Lastname is name[1][/CODE]
Copy linkTweet thisAlerts:
@Harry7authorJul 31.2007 — Works a treat, thanks very much.
×

Success!

Help @Harry7 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.7,
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: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

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

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