how to return user input from jqueru ui dialog box

i want to open a jquery ui dialog box and the box will have an input field which will take username.i want that when user presses ok key on dialog box , the dialog shud return the username back to jquery somehow

$("#dialog").dialog({ autoOpen: false, width: 600, buttons: { "Ok": function() { $(this).dialog("close");}} });

-------------Problems Reply------------

A dialog is asynchronous, which makes it meaningless to "return" something.
You can, however, use one of the callback functions to perform actions with the user input.
For example, using the 'OK' button callback:

$("#dialog")
.append(
$("<input>")
.attr({
"type" : "text",
"id" : "user-input"
})
)
.dialog({
autoOpen: false,
width: 600,
buttons: {
"Ok": function() {
alert( $("#user-input").val() );
$(this).dialog("close");
}}
});

If you just have a div on your page with ID dialog that contains the input field, just select it using a regular jQuery selector when the user presses OK.

Try this on "OK" funcion

var myvalue= $("#yourinputtext").val();
alert(myvalue);

You can capture the value in the ok button click handler, and then do with it as your require:

$("#dialog").dialog({
autoOpen: false,
width: 600,
buttons: {
"Ok": function() {
var inputValue = $("#myInput").val();
// do stuff with the value...

$(this).dialog("close");}
}
}
);

Category:php Views:0 Time:2012-04-30

Related post

Copyright (C) dskims.com, All Rights Reserved.

processed in 0.102 (s). 11 q(s)