Jquery Dialog doesnt show - javascript

I want to generate a dialog box that gets password from user, here's a bit my code.
<html>
<head>
<script type="text/javascript" src="jquery.min.js"></script>
<link href="http://code.jquery.com/ui/1.10.4/themes/ui-lightness/jquery-ui.css" rel="stylesheet">
<script src="http://code.jquery.com/jquery-1.10.2.js"></script>
<script src="http://code.jquery.com/ui/1.10.4/jquery-ui.js"></script>
</head>
<body>
<input type='button' id='btnDelete' name='btnDelete' value='Delete' onclick='deleteRecord(".$row['ID'].")'/>
<div id="delete-dialog" style="display: none;" title="Delete Record">
<label>Please type in admin's password:</label></br>
<input type='password' size='25' id='inpAdminPassword'/>
</div>
</body>
</html>
JS
function deleteRecord(ID){
var answer = confirm("Are you sure you want to delete this record?");
if(answer == true){
$( "#delete-dialog" ).dialog( "open" );
}
}
$(document).ready(function() {
$( "#delete-dialog" ).dialog({
autoOpen: false,
});
Somehow, the dialog box doesn't show, what must be missing?
I have also tried and included this code, but still it doesn't work.
$(document).ready(function() {
$( "#delete-dialog" ).dialog({
autoOpen: false,
});
$("#delete-dialog").dialog({
modal: true,
autoOpen: false,
height: 255,
width: 300,
buttons: {
"Delete": function() {
var password = document.getElementById('sessionPW').value;
var adminpw = document.getElementById('inpAdminPassword').value;
alert(password);
if(password == adminpw){
window.location = "deleteThreat.php?threatID="+ID;
}
},
Cancel: function() {
$( this ).dialog( "close" );
}
}
});
});

I just was trying your first solution and making the confirmation like this works for me:
js:
$("#delete-dialog").dialog({
autoOpen: false,
});
$("#open").click(function () {
if (confirm("are you sure?")) {
$("#delete-dialog").dialog("open");
}
});
html:
<div id="delete-dialog" style="display: none;" title="Delete Record">
<label>Please type in admin's password:</label></br>
<input type='password' size='25' id='inpAdminPassword'/>
</div>
<button id="open" >Open</button>

Related

jquery dialog post if true

I have the following code example and I am trying to make a post request only if the user clicks the Yes button. If the user clicks the No button nothing should happen. Thanks for any help and hints.
<html>
<head>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<link href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/themes/smoothness/jquery-ui.css"
rel="stylesheet" />
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js"></script>
</head>
<body>
<form action="" method="post">
<button id="save" onclick="return ConfirmDialog('this is a test')">Save</button>
</form>
<script>
function ConfirmDialog(message) {
$('<div></div>').appendTo('body')
.html('<div><h6>' + message + '?</h6></div>')
.dialog({
modal: true,
title: 'Delete message to use',
zIndex: 10000,
autoOpen: true,
width: 'auto',
resizable: false,
width: 400,
buttons: {
Yes: function () {
// $(obj).removeAttr('onclick');
// $(obj).parents('.Parent').remove();
//$('body').append('<h1>Confirm Dialog Result: <i>Yes</i></h1>');
$(this).dialog("close");
return true;
},
No: function () {
//$('body').append('<h1>Confirm Dialog Result: <i>No</i></h1>');
$(this).dialog("close");
return false;
}
},
close: function (event, ui) {
$(this).remove();
}
});
};
</script>
</body>
</html>
The issue is that your button is by default of type="submit", you can change it to type="button" and execute your functions normally:
function ConfirmDialog(message) {
$('<div></div>').appendTo('body')
.html('<div><h6>' + message + '?</h6></div>')
.dialog({
modal: true,
title: 'Delete message to use',
zIndex: 10000,
autoOpen: true,
width: 'auto',
resizable: false,
width: 400,
buttons: {
Yes: function() {
$('body').append('<h1>Confirm Dialog Result: <i>Yes</i></h1>');
$(this).dialog("close");
return true;
},
No: function() {
$('body').append('<h1>Confirm Dialog Result: <i>No</i></h1>');
$(this).dialog("close");
return false;
}
},
close: function(event, ui) {
$(this).remove();
}
});
};
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<link href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/themes/smoothness/jquery-ui.css" rel="stylesheet" />
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js"></script>
<form action="" method="post">
<button type="button" id="save" onclick="return ConfirmDialog('this is a test')">Save</button>
</form>

How to use datepicker in dynamically created jQuery UI dialog?

I have trouble to active the datepicker() in a dynamically created jQuery UI dialog():
index.html
$(document).ready(function() {
var $loading = $('<img src="./images/loading.gif" alt="loading">');
$('.page-popup').each(function() {
var $dialog = $('<div></div>')
.append($loading.clone());
var $link = $(this).one('click', function() {
$dialog
.load($link.attr('href'))
.dialog({
title: $link.attr('title'),
width: 600,
height: 300
});
$link.click(function() {
$dialog.dialog('open');
return false;
});
return false;
});
});
$( ".datepicker" ).datepicker({
dateFormat: "yy-mm-dd"
});
});
The external page which gets loaded by a link like that:
Input
it has just a form to select or correct the date:
input.html
<form method="post" action="?">
<input type="text" name="date" value="2000-01-01" class="datepicker">
<input type="submit">
</form>
How can I activate the datepicker for the different dialogs?
Render the datepicker in the open event of the dialog as follows.
$dialog
.load($link.attr('href'))
.dialog({
title: $link.attr('title'),
width: 600,
height: 300,
open: function(){
$( ".datepicker" ).datepicker({
dateFormat: "yy-mm-dd"
});
}
});
The problem was that the subpage can not reload jquery.js and jquery-ui.js. So here my solution:
index.html
<html>
<head>
<script type="text/javascript" src="./js/jquery-1.11.2.min.js"></script>
<script type="text/javascript" src="./js/jquery-ui.js"></script>
<script type="text/javascript">
$(document).ready(function() {
var $loading = $('<img src="./images/loading.gif" alt="loading">');
$('.page-popup').each(function() {
var $dialog = $('<div></div>').append($loading.clone());
var $link = $(this).one('click', function() {
$dialog
.load($link.attr('href'))
.dialog({
title: $link.attr('title'),
width: 600,
height: 300
});
$link.click(function() {
$dialog.dialog('open');
return false;
});
return false;
});
});
$( ".datepicker" ).datepicker({
dateFormat: "yy-mm-dd"
});
});
</script>
</head>
<body>
Input
</body>
</html>
input.html
<html>
<head>
<!-- Don't load jquery and jquery-ui again!!! -->
<script type="text/javascript">
$( ".datepicker" ).datepicker({
dateFormat: "yy-mm-dd"
});
</script>
</head>
<body>
<form method="post" action="?">
<input type="text" name="date" value="2000-01-01" class="datepicker">
<input type="submit">
</form>
</body>
</html>

JQuery Dialog tool bar with drop down button instead of title

lI would like to add a Toolbar or nav bar with a dropdown button instead of the title "?ToolbarHTMLCodeHere?" in my JQuery Dialog window. There should be drop down button with the name "File" in the toolbar when the drop down openes there should be a button inside called "Save".
Does anybody know how to do that?
function openDialog(){
$(function() { // open popup window
$( "#dialog" ).dialog({
create: function (event, ui) {
$(".ui-dialog-title").html("?ToolBarHTMLCodeHere?");
},
width: 250,
height: 150,
modal: true,
resizable: false
});});
}
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
<button type="button" id="Browse" onclick="openDialog()">Start dialog</button> <!--Create Button-->
<div id="dialog" title="Basic dialog" >
What i have until now is this (but its so ugly, hopefully somebody has a better solution):
function openDialog(){
$(function() { // open popup window
$( "#dialog" ).dialog({
create: function (event, ui) {
$(".ui-dialog-title").html("<div class='actions'><a id='TakeAction'>File</a><ul id='actions'><li>Save</li></ul></div>");
},
width: 250,
height: 150,
modal: true,
resizable: false
});});
}
ul#actions
{
display:none;
}
.actions:hover ul#actions
{
display: block;
}
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
<button type="button" id="Browse" onclick="openDialog()">Start dialog</button> <!--Create Button-->
<div id="dialog" title="Basic dialog" >

Javascript UI Dialog does not open first time

I am trying to use the jQuery UI Dialog. But it will not open first time. Consider:
<html>
<head>
<link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/themes/smoothness/jquery-ui.css" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.10.4/jquery-ui.min.js"></script>
<script src="dialog.js"></script>
</head>
<body>
<p>Hello</p>
<div id="dialog" title="Alert" style="display: none;"></div>
</body>
</html>
where dialog.js is:
$(document).ready(function(){
showAlert("1");
showAlert("2");
});
function showAlert(str) {
$( "#dialog" ).html(str);
$( "#dialog" ).dialog({
modal: true,
title: "Alert",
buttons: {
"OK": function() {
document.getElementById("submit").value="Submit";
$( this ).dialog( "close" );
}
}
});
}
This will only show the second dialog, the first dialog (with text "1") seems to be simply ignored..
See also jQuery UI Dialog - Won't open the first time.

JQuery UI Dialog displaying, not working as dialog

Problem:
The dialog div is displaying without the buttons being pressed, and does not appear as an overlay when I press them. I'm tearing my hair out, so thanks in advance.
Code:
Includes:
<script src="js/jquery-1.5.1.min.js"></script>
<script src="js/ui/jquery.ui.core.js"></script>
<script src="js/ui/jquery.ui.widget.js"></script>
<script src="js/ui/jquery.ui.position.js"></script>
<script src="js/ui/jquery.ui.autocomplete.js"></script>
<script src="js/ui/jquery.ui.dialog.js"></script>
Css:
<link rel="stylesheet" type="text/css" href="css/jquery.ui.autocomplete.
<link rel="stylesheet" type="text/css" href="css/jquery.ui.all.
<link rel="stylesheet" type="text/css" href="css/jquery.ui.theme.
<link rel="stylesheet" type="text/css" href="css/jquery.ui.dialog.css" />
Buttons: <a class="phoneadder">Stuff</a>
Scripts:
<script>
$( "#dialog-form" ).dialog({
autoOpen: false,
height: 300,
width: 350,
modal: true
}
);
$( ".phoneadder" ).click(function() {
$( "#dialog-form" ).dialog( "open" );
return false;
});
</script>
Dialog:
<div id="dialog-form" title="Create new phone">
<p>All form fields are required.</p>
<form>
<fieldset>
...some html here
</fieldset>
</form>
</div>
Place the initializer in your document.ready, or as shorthand:
$(function() { $("#dialog-form").dialog(autoOpen... ); } );
Alternatively, make sure your scripts are run after the div is created, so like, in the footer.
Try putting your jQuery code in the $(document).ready function like this:
$(document).ready(function () {
/// your code here
});
Try this,
$(function()
{
$( ".phoneadder" ).click(function() {
$( "#dialog-form" ).dialog({
height: xxx,
width: xxx,
modal: true
});
return false;
});
});
Why don't you just put the dialog function in the click event handler?
<script>
$(function()
{
$( ".phoneadder" ).click(function() {
$( "#dialog-form" ).dialog({
height: 300,
width: 350,
modal: true
});
return false;
});
});
</script>

Categories