Hi I am using a framework called CodeIgniter and its a sample of MVC. I need a popup box where it will display the subvalues of an application however my dialog box is not working everytime I echo it. but you see i need to loop the dialog box for different values. my code is below
<?php
foreach($people as $row){
echo"<div id='dialog' title='Basic dialog'>".$row->app_name."</div>";
echo "<button id='opener'>".$row->app_name."</button>";}
?>
My javascrip code is fro jquery
<script>
$(function() {
$( "#dialog" ).dialog({
autoOpen: false,
show: {
effect: "blind",
duration: 1000
},
hide: {
effect: "explode",
duration: 1000
}
});
$( "#opener" ).click(function() {
$( "#dialog" ).dialog( "open" );
});
});
</script>
Use event delegation
$(document).on("click" , "#opener" ,function() {
$( "#dialog" ).dialog( "open" );
});
Update the code as below:
<?php
$i = 1;
foreach($people as $row){
echo"<div id='dialog". $i."' title='Basic dialog'>".$row->app_name."</div>";
echo "<button id='opener". $i."'>".$row->app_name."</button>";
?>
<script>
$(function() {
$( "#dialog<?php echo $i?>" ).dialog({
autoOpen: false,
show: {
effect: "blind",
duration: 1000
},
hide: {
effect: "explode",
duration: 1000
}
});
$( "#opener<?php echo $i?>" ).click(function() {
$( "#dialog<?php echo $i?>" ).dialog( "open" );
});
});
</script>
<?php
$i++;
}
?>
Basically there will be multiple popup and you need to give unique id to each popup and button.
to use id in this situation is not good idea ... you should change id to class
echo "<button class='opener'>".$row->app_name."</button>";
then
$( ".opener" ).click(function() {
$( "#dialog" ).dialog( "open" );
});
id is unique you should use a class
Enjoy :)
Related
I'm trying to open a dialog, please see comment below:
var user_ids = $('.user_ids:checked').map(function() {
return this.value;
}).get();
var opt = {
autoOpen: false,
modal: true,
width: 550,
height:650,
title: 'Dialog'
};
tried this one but
this wont trigger open dialog
$("#dialog-confirm")
.dialog(opt)
.data('uids','user_ids')
.dialog({
open: function( event, ui ) {
alert('do something!');
},buttons:{
'Confirm': function() {
//do something
$(this).dialog('close');
},
'Cancel': function() {
$(this).dialog('close');
}
}
});
this one successfully open the dialog box
but i want to put the Confirm and Cancel button
$("#dialog-confirm")
.dialog(opt)
.data('uids','user_ids')
.dialog('open');
});
how can i open the dialog with button triggers?
According to the jQuery UI documentation: http://api.jqueryui.com/dialog/#option-buttonsThis is how you put buttons inside your dialog
$(document).ready(function(){
var user_ids = $('.user_ids:checked').map(function() {
return this.value;
}).get();
var opt = {
autoOpen: true,
modal: true,
width: 300,
height:300,
title: 'Dialog'
};
$( ".selector" )
.dialog(opt)
.data('uids','user_ids')
.dialog({
buttons: [
{
text: "Confirm",
icon: "ui-icon-heart",
click: function() {
console.log("confirmed");
}
},
{
text: "Cancel",
icon: "ui-icon-heart",
click: function() {
$( this ).dialog( "close" );
}
}
]
});
$( ".selector" ).dialog( "open" );
});
<script
src="https://code.jquery.com/jquery-3.3.1.min.js"
integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8="
crossorigin="anonymous"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.css">
<script
src="https://code.jquery.com/ui/1.12.1/jquery-ui.min.js"
integrity="sha256-VazP97ZCwtekAsvgPBSUwPFKdrwD3unUfSGVYrahUqU="
crossorigin="anonymous"></script>
<body>
<div class="selector" title="Basic dialog">
<p>This is the default dialog which is useful for displaying information. The dialog window can be moved, resized and closed with the 'x' icon.</p>
</div>
</body>
So I've got this little accordion menu I made using jQuery and php.
It works well apart from the fact that when I click hide all items it opens everything then closes it, when show all is clicked it hides everything then shows it.
I want if i press hide all to hide it straight away without showing everything first and the other way around when show all is clicked.
I'm using count() to count the items in the menu then incrementing it by one when the function ends.
Anyway, here's the code:
jQuery:
<script type="text/javascript">
$ = jQuery;
$( document ).ready(function () {
$( "#heading_<?php echo $count; ?>, .personal-lessons-show-all, .personal-lessons-hide-all" ).on("click", function () {
$( "#lessons_<?php echo $count; ?>" ).slideToggle().css( "display", "block" );
$( "body" ).css( "background-color", "#eee" );
$( ".right-purple-background" ).css( "height", "1124px" );
});
$( ".personal-lessons-show-all" ).on( "click", function () {
$( "#lessons_<?php echo $count; ?>" ).slideDown();
$( ".personal-lessons-hide-all" ).show();
$( "body" ).css( "background-color", "#eee" );
$( ".right-purple-background" ).css( "height", "1124px" );
});
$( ".personal-lessons-hide-all" ).on( "click", function () {
$( "#lessons_<?php echo $count; ?>" ).slideUp();
$( ".personal-lessons-hide-all" ).hide();
$( "body" ).css( "background-color", "white" );
$( ".right-purple-background" ).css( "height", "1200px" );
});
$( ".bordered-title" ).on( "hover", function () {
$( this ).css( "cursor", "pointer" );
});
});
</script>
And the php:
<?php
// Loop through all of the lesson categories
$count = 0;
foreach($lessons as $key => $val){
$count++;
// Get personal lessons for logged in user
$personal_lessons = get_user_meta(get_current_user_id(), 'personal-lessons', true);
$yes_to_all = false;
if(empty($personal_lessons[$_GET['course']]) || !$personal_lessons[$_GET['course']]){
$yes_to_all = true;
}
$category_name = $wpdb->get_row("SELECT name FROM mdl_course_categories WHERE id = '$key'");
?>
<p class="bordered-title" id="heading_<?php echo $count; ?>"><?php echo $category_name->name; ?></p>
<div class="table-responsive">
<table id="lessons_<?php echo $count; ?>" class="lessonsTable table-responsive">
<?php
I am having an issue with Dialogs in jquery, I have a query that plops up to 4 items of data into a div, in a loop. I want to have each row available for more information via a dialog box.
IN HEAD TAG:
<link rel="stylesheet"
href="http://code.jquery.com/ui/1.10.2/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.2/jquery-ui.js"></script>
<script>
$(function() {
$( ".dialog" ).dialog({
autoOpen: false,
show: {
effect: "blind",
duration: 1000
},
hide: {
effect: "explode",
duration: 500
}
});
$( ".opener" ).click(function() {
$( ".dialog" ).dialog( "open" );
});
});
</script>
PHP:
foreach($veh as $v){
echo '<div class="block">';
$sql = "SELECT * FROM table";
$result = $dbh->query($sql);
$row = $result->fetchall(PDO::FETCH_ASSOC);
foreach($row as $r){
echo '<div class="effect6">'.strtoupper($r['col_name']).'</div>';
echo '<div id="dialog" title="'.$r['eas_no'].'">Text</div>';
echo '<button id="opener">Open</button>';
}
echo '</div>';
}
EDIT
Every Single Dialog box now opens...
Try changing your code to this:
<script>
$(function() {
$( ".dialog" ).dialog({
autoOpen: false,
show: {
effect: "blind",
duration: 1000
},
hide: {
effect: "explode",
duration: 500
}
});
$( ".opener" ).bind("click", function() {
var selectorClass = ".dialogDiv" + $(this).attr("id");
$(selectorClass).dialog( "open" );
});
});
</script>
and
$tmp = 0;
foreach($row as $r) {
echo '<div class="effect6">'.strtoupper($r['col_name']).'</div>';
echo '<div class="dialogDiv'.$tmp.' dialog" title="'.$r['eas_no'].'">Text</div>';
echo '<button class="opener" id="'.$tmp.'">Open</button>';
$tmp++;
}
You are making multiple things with same id (dialog and opener). id are supposed to be unique on page
I am using a fullcalendar:-
http://arshaw.com/fullcalendar/
and I am using jquery .post to get a parameter back to the same page to generate some result, and this is working well.
At the same time, I wish to use jquery ui dialogue to hold the displayed contents. While pasting the sample codes from official site, the example works. However, when combining the .post output with dialogue, it was not successful.
I would like to seek help in combining the below 2 sets of scripts:-
//for generating .post output (working!)
<script>
function event_details(thevalue){
$.post('module/calendar/event_details.php',{
eid:thevalue},
function(output){
$('#theeventmsg').html(output);
});
}
</script>
<div id='theeventmsg'></div>
//jquery ui dialogue (working!)
<script>
// increase the default animation speed to exaggerate the effect
$.fx.speeds._default = 1000;
$(function() {
$( "#dialog" ).dialog({
autoOpen: true,
show: "blind",
hide: "explode"
});
$( "#opener" ).click(function() {
$( "#dialog" ).dialog( "open" );
return false;
});
});
</script>
<div class="demo">
<div id="dialog" title="Basic dialog">
<p>This is an animated dialog which is useful for displaying information. The dialog window can be moved, resized and closed with the 'x' icon.</p>
</div>
<button id="opener">Open Dialog</button>
</div><!-- End demo -->
Can help??? Thanks a lot!!
Try something like this:
<script>
$.fx.speeds._default = 1000;
$(document).ready(function() {
$( "#dialog" ).dialog({ autoOpen: false });
$('#button').click(function () {
var data = { ... };
$.post('module/calendar/event_details.php', data, function (output) {
$('#dialog p').html(output);
$( "#dialog" ).dialog("open");
});
});
});
</script>
<div id="dialog">
<p>content</p>
</div>
<button id="button">button</button>
Or:
<script>
$(document).ready(function () {
function eventdetail(thevalue) {
$.post('event_details.php', { eid: thevalue }, function (output) {
$('#dialog p').html(output);
$("#dialog").dialog({ autoOpen: true });
});
}
$('#button').click(function () { eventdetail('value'); });
});
</script>
<div id="dialog">
<p>content</p>
</div>
<button id="button">button</button>
Here's my problem...
I have the following jQuery UI script :
<script>
$(function() {
$( "#dialog" ).dialog({
autoOpen: false,
show: "slideUp",
hide: "slideDown",
height: "300",
width: "400",
title: "Test pop-up",
buttons: {
"Close": function(){
$(this).dialog("close");
}
}
}
);
$( "p.diag").click(function(e) {
var monUrl = 'test2.php';
$('#dialog').load(monUrl, function(response, status) {
$('#test_dialog').html(response);
});
e.preventDefault();
});
$( "p.diag").click(function() {
$( "#dialog" ).dialog("open");
});
It's a pretty simple code, it opens correctly my dialog box when I click on a p.diag class, but it won't re open after I close it.
The test2.php page just print a "lol" with a echo "lol";
And here's my HTML :
<div style="height: 200px; min-height: 109px; width: auto;" class="ui-dialog-content ui-widget-content" id="dialog">
</div>
Thanks !
Pleas remove e.preventDefault();
see this demo: http://jsfiddle.net/ngwJ3/
Reason: http://api.jquery.com/event.preventDefault/ : If this method is called, the default action of the event will not be triggered.
Hope this help :)