Mark Mark - 1 year ago 83
Javascript Question

How to get input via a popup and place text in a variable via javascript/jquery

I have a button on my page. When clicked a popup box should appear allowing the user to enter text. When OK/Submit is pressed, my jscript will then perform some functions using that inputted data. Very straightforward, but I just can't figure out how to do this.


Answer Source

in it's simplest form, you could use prompt(question, default): (taken from w3schools:

function myFunction(){
    var x;
    var name=prompt("Please enter your name","Harry Potter");
    if (name!=null){
       x="Hello " + name + "! How are you today?";

anything else would require lots of javascript & CSS to create layers with buttons and click events on those buttons

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download