Prompting and Prodding

prompt

Poking and prodding to get the information we want…this is usually something we do with our teenagers, but we can prompt our end users for information by using built in funcionality within JavaScript. The function/method we are going to use is entitled, prompt().

Now one caveat before we dive into this subject…this function is not one I would suggest using often. There are some pitfalls with it, especially when it comes to validation of data. Nevertheless, it is a handy function to know when you want quick feedback. Here is how it works…

[code lang=”js”]
// Create variable to house end user info var userInfo;
// Prompt the user to enter information
userInfo = prompt("Please enter some information.");
// Output the end user’s information to the screen
document.write("You entered: " + userInfo);
[/code]

So, as you can see from the code above, we can prompt the end user for some information. They can then enter that information. We can store it in a variable and then do what we would like to do with it. Below is what the end user would see when our code runs…

prompt

prompt with information

prompt screen display

So, we can quickly and easily gather information from our users. I mentioned previously about some pitfalls with this. I will be honest, I do not use this too often because of the pitfalls. Forms are a better way of gathering the necessary information. Within a prompt, there is not a way to limit or dictate what the end user puts in. It is simply a text box with no parameters. Speaking of being a text box, numbers can be an issue. If you ask an end user to enter a number, that number comes across as a data type of string. So it needs to be converted to an integer using the Number() function.

With all of the issues and trappings that surround the prompt() that limits its usage, it is still a handy, quick little function in certain circumstances.

Happy Coding!

More To Explore

Secure Login Access with Username and Password on Mobile Device and Laptop
Code

A gentle intro to the Credential Management API

The Credential Management API lets your site securely store and retrieve user credentials through the browser’s built‑in manager—no brittle autofill hacks required. In our demo, a successful login stores a PasswordCredential, and a single click later retrieves and auto-fills it for returning users. It’s a progressive enhancement: your form still works everywhere, but supported browsers deliver a faster, lower-friction sign-in. Pair it with proper autocomplete attributes today, and plan for WebAuthn/passkeys to level up tomorrow.

Share This Post

small_c_popup.png

Need help?

Let's have a chat...


Login

Jump Back In!

Here at Webolution Designs, we love to learn. This includes sharing things we have learned with you. 

Register

Begin Your Learning Journey Today!

Come back inside to continue your learning journey.