Multiple Dialog Boxes - 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

Related

dialog in jquery ui won't open

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>

jQuery and php accordion menu doing weird thing

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 need to get data from mysql DB and put it to a json array and use the json array for textbox auto complete

i need to get data from mysql DB and put it to a json array and use the json array for textbox auto complete. i can do this with separate php for load the data from db and use it in the ajax.. but i am trying to do this with one php file.. is this possible.. how to do this.
<script>
$(document).on('keyup','.jornal', function(){
var thisRow = $(this).data('value');
if(event.which != 13){
//itemSearchDisables(thisRow);
}
autoTypeNo2=1 ;
autoTypeNo1=0 ;
$(this).autocomplete({
source: function( request, response ) {
$.ajax({
url : 'AJAX_Requst/bill_itemDetail.php',
dataType: "json",
method: 'post',
data: {
ID: request.term
},
success: function( data ) {
response( $.map( data, function( item ) {
var code = item.split("|");
if(code[0] == 'Login Please'){
//window.location = '../login.php';
}
return {
label: code[autoTypeNo2] + ' | '+ code[3],
value: code[autoTypeNo1],
data : item
}
}));
}
});
},
autoFocus: true,
minLength: 0,
select: function( event, ui ) {
var names = ui.item.data.split("|");
id_arr = $(this).attr('id');
id = id_arr.split("_");
//itemSearchEnables(thisRow);
$('#itemNo_'+id[1]).val(names[0]);
$('#itemName_'+id[1]).text(names[1]);
}
});
});
</script>
This is what i am done up to now to load data..and it is working fine
If my understanding is correct, create the json array in the same php file and pass that array to the javascript function.. It would be some thing like below
<script>
$(function() {
var availableTags = [<?php $jsonArray ?>];
$( "#tags" ).autocomplete({
source: availableTags
});
});
</script>
in that case try using this
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>jQuery UI Autocomplete - Custom data and display</title>
<link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
<link rel="stylesheet" href="/resources/demos/style.css">
<style>
#project-label {
display: block;
font-weight: bold;
margin-bottom: 1em;
}
#project-icon {
float: left;
height: 32px;
width: 32px;
}
#project-description {
margin: 0;
padding: 0;
}
</style>
<script>
$(function() {
var projects = [
{
value: "jquery",
label: "jQuery",
desc: "the write less, do more, JavaScript library",
icon: "jquery_32x32.png"
},
{
value: "jquery-ui",
label: "jQuery UI",
desc: "the official user interface library for jQuery",
icon: "jqueryui_32x32.png"
},
{
value: "sizzlejs",
label: "Sizzle JS",
desc: "a pure-JavaScript CSS selector engine",
icon: "sizzlejs_32x32.png"
}
];
$( "#project" ).autocomplete({
minLength: 0,
source: projects,
focus: function( event, ui ) {
$( "#project" ).val( ui.item.label );
return false;
},
select: function( event, ui ) {
$( "#project" ).val( ui.item.label );
$( "#project-id" ).val( ui.item.value );
$( "#project-description" ).html( ui.item.desc );
$( "#project-icon" ).attr( "src", "images/" + ui.item.icon );
return false;
}
})
.autocomplete( "instance" )._renderItem = function( ul, item ) {
return $( "<li>" )
.append( "<a>" + item.label + "<br>" + item.desc + "</a>" )
.appendTo( ul );
};
});
</script>
</head>
<body>
<div id="project-label">Select a project (type "j" for a start):</div>
<img id="project-icon" src="images/transparent_1x1.png" class="ui-state-default" alt="">
<input id="project">
<input type="hidden" id="project-id">
<p id="project-description"></p>
</body>
</html>
I think it is possible from my point of view. This way you don't have to post ajax form in autocomplete function too.
First you retrieve the data from MySQL database as usual.
Next, you store those data in the javascript var.
Last, you can use the var for textbox autocomplete.

php loop pop up box and dialog from jquery

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 :)

full calendar + jquery ui dialogue

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>

Categories