jquery dialog open only first time - php

I have jquery dialog and when i click over the button it open but only first time when i close it and click second time over the same button it not appears. Here is my code :
Script:
$(function () {
$("#dialogPicture").dialog({
autoOpen: false
});
$(".buttonClass").on("click", function () {
// get the div element with the id dialogClass contained at the same scope as button!
var id = ($(this).siblings(".dialogClass").attr("id"));
$("#" + id).dialog({
autoOpen: false
});
$("#" + id).dialog("open").css({
"font-size": "13px"
});
});
});
HTML :
<td>
<?=$row['NOMER']?><input id="btn2" class="buttonClass" type="button" value="ВИЖ" />
<div class="dialogClass" id="dialogPicture_<?=$row['NOMER'];?>" style="display:none;">
<table class="bilet">
<tr>
<h2>
<td colspan="4">
<div align="center"><strong>ПРЕВОЗЕН БИЛЕТ</strong></div>
</td>
</h2>
</tr>
<p>
<tr >
<td colspan="2" align="right">
</table>
</div>

I think the problem is that on each button click you create a new instance of dialog box.
Try initializing all the dialog boxes in the beginning of the script and let the buttons only open them.
Another issue is that the dialog div is no longer on the table after initialization:
<div id="btn<?=$row['NOMER']?>".....
$(function () {
$(".dialogClass").each(function(){
$(this).dialog({ autoOpen: false });
});
$(".buttonClass").on("click", function () {
// get the div element with the id dialogClass contained at the same scope as button!
var btnId = ($(this).attr("id"));
btnId = btnId.replace("btn","");
$("#dialogPicture_" + btnId).dialog("open").css({
"font-size": "13px"
});
});
});

You can try out this.
You should use this Code to destroy the Dialog in Button Section
$("#TestMenuDialog").dialog("close").dialog("destroy").remove();
var NewDialog = $('<div id="TestMenuDialog"><p style="color:Red;style="font-size:7x;font-weight:normal">' + Message + '</p></div>');
NewDialog.dialog({
modal: false,
title: "Test Dialog",
height: 200,
width: 375,
show: 'clip',
hide: 'clip',
buttons: [
{ text: "OK", click: function () { $(this).dialog("close").dialog("destroy").remove(); } }
]
});
check the Jfiddle Link It works fine
http://jsfiddle.net/zpP3c/1/

Related

get data on mousehover for different id

I have a listing of products each with differnt ID. Now on frontend I want to get prodouct data(say, name,price and a addtocart button) on mousover.
Here is my code:
This is in loop to get all products:
HTML:
<div class="prod">
<a class="product-image pi_470" title="Cushion Tsavorites" href="/tsavorite/cushion-tsavorites-1328.html"><img height="135" width="135" alt="Cushion Tsavorites" src="/small_image.jpg"></a>
<div style="display: none; margin: -65px 0px 0px 5px; position: absolute; z-index: 30;" class="mouse_hover_470">
<input type="hidden" id="prod_id" value="470">
<h2 class="product-name"><a title="Cushion Tsavorites" href="/tsavorite/cushion-tsavorites-1328.html">Cushion Tsavorites</a></h2>
<div class="price-box">
<span id="product-price-470" class="regular-price">
<span class="price">$387.15</span>
</span>
</div>
<div class="actions">
<button onclick="setLocation('http://dev614.trigma.us/chocolate/index.php/checkout/cart/add/uenc/aHR0cDovL2RldjYxNC50cmlnbWEudXMvY2hvY29sYXRlL2luZGV4LnBocC90c2F2b3JpdGUuaHRtbA,,/product/470/form_key/4BR7w0TqeeO9AC0g/')" class="button btn-cart" title="Add to Cart" type="button"><span><span>Add to Cart</span></span></button>
</div>
</div>
</div>
jQuery:
jQuery(document).ready(function() {
var bla = jQuery('#prod_id').val();
jQuery(".pi_" + bla).mouseover(function() {
//alert("hello");
jQuery(".mouse_hover_" + bla).css("display", "block");
});
jQuery(".pi_" + bla).mouseout(function() {
jQuery(".mouse_hover_" + bla).css("display", "none");
});
});
But Iam getting only data of first product on mouseover. Its not working for rest of products
Looks like you are executing the above block of code in a loop, once per each product. In that case the problem is jQuery('#prod_id').val(); it will always return the value of first element with id prod_id.
In your case you don't have to do that, you can
jQuery(function ($) {
$('.prod .product-image').hover(function () {
$(this).next().show();
}, function () {
$(this).next().hide();
})
});
There is a much, much easier way to do this:
jQuery(document).ready(function() {
jQuery(".product-image").hover(function() {
$(this).next().show();
}, function() {
$(this).next().hide();
});
});
Demo: JSBin
You can use each() function in jQuery
NOTE: Instead of using id="prod_id", use class, i.e class="prod_id". Since you told that the div is dynamically created it is using the same id attribute
Now loop the product div on ready function
jQuery(document).ready(function() {
jQuery('.prod').each(function(){
var bla = jQuery('.prod_id').val();
jQuery(".pi_" + bla).on('mouseover',function() {
//alert("hello");
jQuery(".mouse_hover_" + bla).css("display", "block");
});
jQuery(".pi_" + bla).on('mouseout',function() {
jQuery(".mouse_hover_" + bla).css("display", "none");
});
});
});
You can checkout this jQuery each()
Ashi,
try using
var bla = jQuery(input[id*='prod_id']).val();
instead of
var bla = jQuery('#prod_id').val();
This will give you all the hidden inputs so loop all of them and bind the mouseover event.
For example:
jQuery(input[id*='prod_id']).each(function(){
var bla = jQuery(this).val();
//carry out your logic..
// you can use jquery().live('mouseover'function(){}) for dynamically created html
});
Hope this will work!!
Cheers!!
function handler(ev) {
var target = $(ev.target);
var elId = target.attr('id');
if( target.is(".el") ) {
alert('The mouse was over'+ elId );
}
}
$(".el").mouseleave(handler);
http://jsfiddle.net/roXon/dJgf4/

Open dialog box with contents php traversed from a database using js/jquery

I am creating an image map with buttons. The buttons are created by php:
while($pc = mysql_fetch_array($result)){
if ($pc['Online_Status']==0){
$class = 'workstation-offline';
}
else{
$class = 'workstation-online';
}
echo "\r\n\t\t\t".'<button class="'.$class.'" id="'.$pc['PCID'].'" title= "'.$pc['PCID'].'>';
}
When the page loads, traverse.php dictates what class the button will be. In my css, the workstation-offline will be green, and red if offline. traverse.php also loads data from a database.
This is the html code:
<div class="image_map" style="background-image: url('image.jpg');">
<?php
include("traverse.php");
?>
</div>
What I'd like to happen is when a button is clicked, a dialog box will open and display data about the station with the ID "pc['PCID']" in a table like:
<h3>"The ID of the Button"</h3>
<table>
<tr>
<td>IP Address</td>
<td>pc['ipAddress']</td>
</tr>
<tr>
<td>MAC Address</td>
<td>pc['macAddress']</td>
</tr>
<tr>
<td>Other Info</td>
<td>pc['otherInfo']</td>
</tr>
</table>
How can I do that using js/jquery?
I would use jquery-ui modal dialog box. (http://jqueryui.com)
You could load data on the fly like this. Here's a click handler for the buttons that will create a dialog box and then load data from a server side page :
$(document).ready(function () {
$('.workstation-online,.workstation-offline').click(function () {
var url = "put the url to obtain info from database here";
var dialog = $('<div style="display:none" class="loading"></div>').appendTo('body');
dialog.dialog({
resizable: false,
width: 400,
height: 300,
modal: true,
closeText: '',
close: function (event, ui) {
// remove div with all data and events
dialog.remove();
}
});
dialog.load(
url,
function (responseText, textStatus, XMLHttpRequest) {
// remove the loading class
dialog.removeClass('loading');
}
);
return false;
});
});

ajaxForm is not running when used in jquery dialog

why is that ajaxForm is not running in jQuery Dialog modal confirmation whenever it is included in a "Delete Item" button.
Here is my jquery dialog:
<div id="deleteDialogForPartylist" title="Delete this item?">
<form id="deleteDialogForPartylistForm" action="mEdit/editPartylist/storeDataToDb/deleteData.php">
<p><span class="ui-icon ui-icon-alert" style="float: left; margin: 0 7px 20px 0;"></span><span id="acronymOfTheParty" style="font-weight:bolder"></span> will be permanently deleted and cannot be recovered. Are you sure?</p>
<input type="hidden" id="deleteDialogForPartylistHiddenId" name="deleteDialogForPartylistHiddenId">
</form>
</div>
Here is my script
$(function(){
$( "#deleteDialogForPartylist" ).dialog({
autoOpen: false,
resizable: false,
height:225,
hide: 'fade',
modal: true,
buttons: {
Cancel: function() {
$("#deleteDialogForPartylist").dialog('close');
},
"Delete item": function() {
$('#deleteDialogForPartylistForm').ajaxForm({
target: '#partyListInAddCandidate',
type: "post",
success: function(){
alert("Success");
$("#deleteDialogForPartylist").dialog('close');
}
});
}
}
});
});
.ajaxForm() does not submit the form as stated in the documentation of the plugin (http://malsup.com/jquery/form/#api)
In your case you should use .ajaxSubmit() instead, which will instantly submit your form on button-click as already suggested by charlietfl's comment

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>

Unable to reopen dialog box after closing

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

Categories