Mr_Green
Mr_Green

Reputation: 41832

show alert box with Text field in it

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.

Upvotes: 7

Views: 42239

Answers (5)

Matthew Dean
Matthew Dean

Reputation: 552

Just use good old JavaScript:

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

Live Demo

Upvotes: 23

Michael Jasper
Michael Jasper

Reputation: 8068

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 });

Upvotes: 5

coder
coder

Reputation: 13248

Try this:

$(document).ready(function(){
var msg = window.prompt("Write your name", "Name");
alert(msg);
});​

Upvotes: 0

bipen
bipen

Reputation: 36531

"I want to show a Alert Box with TextBox field in it,". alert box with text field is not possible at all..(from what i have learnt till now).... u can use other jquery plugins like dialog

http://jqueryui.com/dialog/

to do the same..

or the classic way using prompt

var name=prompt("Please enter your name","Harry Potter");

Upvotes: 0

nix
nix

Reputation: 3302

You can use JQueryUI Dialog to show a form in a dialog box.

Upvotes: 0

Related Questions