Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

show alert box with Text field in it

Tags:

jquery

I am new to jquery. I want to show a Alert Box with TextBox field in it, whenever the page loads. Something like this:

Enter Your Username: //Title
___________________  //TextBox field (value will be stored in var for later use)

                OK   //Button

I know

var username = "username";  //already entered message
alert(username);   

How to achieve the above Alert Box? should I manually code it?
Giving an example in jQuery is preferable. I am trying to do this for my chat application where username is required to show in the chat. I searched alot but couldn't find any useful related to asp.net and jquery.

like image 432
Mr_Green Avatar asked Nov 29 '22 08:11

Mr_Green


2 Answers

Just use good old JavaScript:

var text = prompt("prompt", "textbox's intial text");

Live Demo

like image 75
Matthew Dean Avatar answered Dec 10 '22 21:12

Matthew Dean


Giving an example in jQuery is preferable.

jQuery Impromptu provides an aesthetic JavaScript Prompt, which is equally easy to call as JavaScripts window.prompt method:

//Simple Prompt
$.prompt('Example 1');

//Opacity of the modal
$.prompt('Example 3',{ opacity: 0.2 });

//Adding Callbacks
function mycallbackfunc(e,v,m,f){
alert('i clicked ' + v);
}

$.prompt('Example 8',{ callback: mycallbackfunc });
like image 43
Michael Jasper Avatar answered Dec 10 '22 21:12

Michael Jasper