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

Code

Exploring the Broadcast Channel API: Inter-Tab Communication

Intercommunication between different contexts (like tabs, iframes or workers) of the same origin has often been a challenge. With the Broadcast Channel API, developers now have a powerful tool to easily communicate between browsing contexts. In this blog post, we’ll dive deep into the capabilities of the Broadcast Channel API, exploring its features, use cases, and how it can be effectively implemented in your projects.

computer, laptop, work place-2982270.jpg
Code

Unlocking Wireless Communication: A Dive into the Bluetooth API

Wireless communication has become an integral part of our daily lives, and Bluetooth technology is at the forefront of this revolution, enabling devices to exchange data over short distances and creating a world more interconnected than ever before. At the heart of this technology lies the Bluetooth Application Programming Interface (API), a powerful tool for developers looking to harness the capabilities of Bluetooth in their applications. In this blog post, we’ll explore what the Bluetooth API is, how it works, and the possibilities it opens up for innovation in wireless communication.

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.