Showing modal-box morethan 1 on a page - php

<< Referring to this thread >>
I want to make several modal-box on a page:
<script>
var grid_modal_options = {
height: 'auto',
width: '80%',
modal: true
};
function showProducts1ModalBox() {
$("#products1_modal_box").dialog(grid_modal_options);
$("#products1_modal_box").parent().appendTo('form:first');
}
function showProducts2ModalBox() {
$("#products2_modal_box").dialog(grid_modal_options);
$("#products2_modal_box").parent().appendTo('form:first');
}
function showProducts3ModalBox() {
$("#products3_modal_box").dialog(grid_modal_options);
$("#products3_modal_box").parent().appendTo('form:first');
}
</script>
<div id="products1_modal_box" title="Products" style="display: none;">
<div class="in">
<div class="grid-12-12">
<form id="products1_modal_box_form" action="#" method="post">
<table>
<thead>
<tr>
<th> </th>
<th>Product</th>
</tr>
</thead>
<!-- Query for read mysql goes here (I skipped this line because it's not the main thing I'm gonna ask since it's run well) /-->
<tbody>
<?php
//read the results
while($fetch = mysqli_fetch_array($r)) {
print "<tr>";
print " <td>Choose</td>";
print " <td>" . $fetch[0] . "</td>"; //$fetch[0] == Product ID
print "</tr>";
}
?>
</tbody>
</table>
</form>
</div>
</div>
</div>
<div id="products2_modal_box" title="Products" style="display: none;">
<!--
The rest goes here (the same with "products1_modal_box")
except:
print " <td>Choose</td>";
/-->
</div>
<div id="products3_modal_box" title="Products" style="display: none;">
<!--
The rest goes here (the same with "products1_modal_box")
except:
print " <td>Choose</td>";
/-->
</div>
And:
<input type='text' id='products1_id_textbox' name='products1_id_textbox' />
<a href='#' onclick='showProducts1ModalBox(); return false;'>Choose products 1</a>
<input type='text' id='products2_id_textbox' name='products2_id_textbox' />
<a href='#' onclick='showProducts2ModalBox(); return false;'>Choose products 2</a>
<input type='text' id='products3_id_textbox' name='products3_id_textbox' />
<a href='#' onclick='showProducts3ModalBox(); return false;'>Choose products 3</a>
Why this doesn't work? When I removed the div "products2_modal_box" and "products3_modal_box", the modal-box for div "products1_modal_box" appear, but when I tried to get back all of them, each modal-box doesn't appear while I clicked the link. What's wrong with the code? Thanks..

This doesn't technically answer your question, but I use jQuery Reveal for modals on my site. Seems a lot easier than what you're trying to do. Here's the source: http://www.zurb.com/playground/reveal-modal-plugin
It's really easy to set up, and you can have multiple modals per page, and can trigger them with an event (such as a click) or dynamically with jquery.
Hope this helps!

Related

JqueryMobile 1.4.0 pass parameter to popup

I'm pretty new to jQuery Mobile and PHP and I'm having an issue where I have a PHP while loop
while ( $row = sasql_fetch_array ( $idresult ) ) {
echo "
<li>
<a href='#' data-rel='popup' data-position-to='window' data-transition='pop'>
<div class='ui-grid-a'>
<div class='ui-block-a'>
<div class='ui-bar ui-bar-a titleRow' style='height:15px'>Identification Type</div>
<div id='idType' class='ui-bar ui-bar-a 'style='height:15px; background-color:transparent; border: none; color: black; font-weight: normal;' >" . $row ['description'] . "</div>
</div>
<div class='ui-block-b'>
<div class='ui-bar ui-bar-a titleRow' style='height:15px'>Details</div>
<div id='idNo' class='ui-bar ui-bar-a ' style='height:15px; background-color:transparent; border: none; color: black; font-weight: normal;'>" . $row ['number'] . "</div>
</div>
</div>
</a>
<a href='#editCustId' data-rel='popup' data-position-to='window' data-transition='pop'>Edit</a>
</li>
";
} // end while
echo "</ul>";
} // end if
When the use clicks on the edit button I need to pass the ID of that particular row. I'm not sure where I should put this in but it could be something like this...? Will this work when there is no form?
<input type="hidden" name="the_id" value='<?php " . $row ['theid'] . " ?>' />
However I can't figure out how to do this. I have tried opening the dialog as a new page ie.
<a href='./editCustId.php?id=" . $row['theid'] . "' data-rel='popup' data-position-to='window' data-transition='pop' class='ui-btn ui-btn-inline ui-icon-edit ui-btn-icon-notext'>Edit</a>
When edit is clicked this popup will open
<div data-role='popup' id='editCustId' data-theme='a' data-overlay-theme='a' data-dismissible='false' style='min-width: 300px;'>
<div data-role='header' data-theme='a'>
<h1>Add ID</h1>
</div>
<div data-role='main' class='ui-content'>
<form id='editId' onsubmit="return false;">
<input type="hidden" name="cust_id" value='<?php echo $custid; ?>' />
<input type="hidden" name="sess_id" value='<?php echo $sid; ?>' />
<!-- <input type="hidden" name="submitted" value="true" /> -->
<div class="ui-field-contain">
<label for="phoneType">Type</label>
<select name="idType" id="idType">
<?php echo $idInnerOptions; ?>
</select>
</div>
<div class="ui-field-contain">
<label for="idDesc">Description</label> <input type="text" name="idDesc" id="idDesc" value="">
</div>
<div class='ui-grid-a'>
<div class='ui-block-a'>
<input type='submit' id="submit" value='Update' class='ui-btn ui-btn-inline' data-transition='pop' />
</div>
<div class='ui-block-b'>
Cancel
</div>
<div id="success" style="color: black;"></div>
</div>
</form>
</div>
</div>
The description and number will contain the relevant info based on which link was clicked.
I've been looking into passing the data through ajax but I'm not really getting what I should be doing?
I Think there are 2 issues here for you to check more:
As i recall, the popup feature of jquery mobile is for code that are inside divs that has the popup data-role. So, what you tried to do is not in the JQM logic. However, JQM also allows you to use iframe in divs with popup data-role so maybe that will be a good solution for you.
Another way to go, could be to dynamicly load the content of the page you want by AJAX to a div that has the popup data-role.
Hope this helps

How to print some specific part of a page via window.print()

i'm working on a form in php mysql. so in my page there is a form and below that i shown the data of that form in table format.now i want to print only the table structure thats why i just made a PRINT button as:
<span style="float:right;">PRINT</span>
but it will print the whole page with form field and table and i just want the tableto print.
Here is the design of my whole page with form and table:
<html>
<head></head>
<body>
<div class="container">
<form class="form-horizontal" action="" method="post" name="userform1" id="company-form" enctype="multipart/form-data">
<?php if($_GET[id]){?>
<fieldset>
<legend>Add Company</legend>
<div class="control-group">
<label class="control-label">Company Name</label>
<div class="controls">
<input type="text" name="company" id="company" value="<?php echo $selup['company']?>">
</div>
</div>
<div class="control-group">another field</div>
<div class="control-group">another field</div>
<div class="control-group">
<div class="controls">
<button type="submit" class="btn" name="submit" id="submit" value="Submit">Submit</button>
</div>
</div>
<table class="table table-bordered">
<tbody>
<tr>
<td>S.No.</td>
<td>Company Name</td>
<td>Type</td>
<td>Action</td>
</tr>
<?php
// to print the records
$select = "select * from company where type='Miscellaneous'";
$query1 = mysql_query($select);
while($value = mysql_fetch_array($query1)){ ?>
<tr>
<td><?php echo $value[id];?></td>
<td><?php echo $value[company ];?></td>
<td><?php echo $value[type];?></td>
<!--<td> </td>-->
<?php /*?><td><?php echo $value[amount];?></td>
<td><?php echo $value[date];?></td><?php */?>
<td><i class="icon-edit"></i>
<i class="icon-trash"></i></td>
</tr><?php }?>
</tbody>
</table>
</fieldset>
<form>
</div>
</body>
so i just want to print the table not whole page.
Use css to hide elements you don't want to print:
#media print {
.control-group {
display: none;
}
}
function printContent(el){
var restorepage = document.body.innerHTML;
var printcontent = document.getElementById(el).innerHTML;
document.body.innerHTML = printcontent;
window.print();
document.body.innerHTML = restorepage;
}
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<h1>My page</h1>
<div id="div1">DIV 1 content...</div>
<button onclick="printContent('div1')">Print Content</button>
<div id="div2">DIV 2 content...</div>
<button onclick="printContent('div2')">Print Content</button>
<p id="p1">Paragraph 1 content...</p>
<button onclick="printContent('p1')">Print Content</button>
</body>
</html>
You could make a print-css (which does the same as #media print, but I think it is cleaner, and you can disable the css include via javascript, if you need it):
<link rel="stylesheet" type="text/css" href="print.css" media="print" />
In that css, you hide all elements which should not get printed, for example:
.wrapper, .header {display: none;}
One posible solution, perhaps not the best option:
1. Open a new window with JS
2. Copy the whole table into the new window (with jQuery for example)
3. Print the new window
4. Close the window
Sure it has a blink effect but It will work.

How create a popup on mouseover depending on the item?

I want to create a popup depending on the item. The text to appear is taken from the database depending on each item.Specifically, I have this code:
{foreach $images as $item}
<div class="icoana" id="container">
<img class="icoane" src="{base_url()}assets/image/{$item->code}/{$item->name}">
<div class="detalii">
<table style="font-size: 25px">
<tr><td>Nume:</td><td>{$item->title}</td> </tr>
<tr><td>Lungime:</td><td>{$item->width}&nbsp cm</td> </tr>
<tr><td>Latime:</td><td>{$item->height}&nbsp cm</td></tr>
</table>
</div>
<div class="despre" id="popup"><img src="{base_url()}assets/image/go.jpg" style="weight: 20px; height:20px;" >Mai multe...</div>
</div>
{/foreach}
and when mouseover div class="despre" I want appear a pop-up with text's description stored in {$item->description}. The pop-up I want to look like this: http://creativeindividual.co.uk/2011/02/create-a-pop-up-div-in-jquery/.I would like a link to an example or source code.
Broadly, what you need to do is two steps
1) Print out the div description in the php code immediately below the div mentioned.
So your code becomes.
{foreach $images as $item}
<div class="icoana" id="container">
<img class="icoane" src="{base_url()}assets/image/{$item->code}/{$item->name}">
<div class="detalii">
<table style="font-size: 25px">
<tr><td>Nume:</td><td>{$item->title}</td> </tr>
<tr><td>Lungime:</td><td>{$item->width}&nbsp cm</td> </tr>
<tr><td>Latime:</td><td>{$item->height}&nbsp cm</td></tr>
</table>
</div>
<div class="despre" id="popup"><img src="{base_url()}assets/image/go.jpg" style="weight: 20px; height:20px;" >Mai multe...</div>
<div class="desc" style="display:hidden">
{$item->description}
</div>
</div>
{/foreach}
2) After that use the same code in the link you provided above and modify the the display part
$(function() {
$('.despre').hover(function(e) {
//Code to show the popup
// Modify to use any standard popup library
// The code below , for now display the desc only.
$(this).next().show();
}, function() {
$(this).next().hide();
});
});
For now this will show and hide the div. You can use any ToolTip library to actually display the popup
Examples here : http://www.1stwebdesigner.com/css/stylish-jquery-tooltip-plugins-webdesign/
Regards
Shreyas N

Integrating JQuery into a CMS controlled environment HTML/CSS/PHP on XAMPP server

I'm having a hard time adding dynamic functionality to my website with JQuery.
<table id="structure">
<tr>
<td id="navigation">
<?php echo public_navigation($sel_subject, $sel_page); ?>
</td>
<td id="page">
<?php if ($sel_page) { ?>
<h2><?php echo htmlentities($sel_page['menu_name']); ?> </h2>
<div class="page-content">
<?php echo strip_tags(nl2br($sel_page['content']), "<b><br><p><a>"); ?>
</div>
<?php } else { ?>
<h2>Welcome to my "to the point" news and blog mix.</h2>
<?php } ?>
<br />
<?php
// garbledeegoo starts here
?>
<p>JScript Practice</p>
<div id="jscriptprac">text</div>
<br />
<h2>To Do</h2>
<form name="checkListForm">
<input type="text" name="checkListItem"/>
</form>
<div id="button">Add!</div>
<br/>
<div class="list"></div>
<?php
// garbledeegoo ends here
?>
</td>
</tr>
</table>
the problem is i cant make jquery tag selectors style my navigation where i have SQL statements that retrieve my content.
$(document).ready(function(){
$("*").hover(function(){
$(this).stop(true, true).animate({ width:"+=25px", padding:"+=25px" });
}, function() {
$(this).stop(true, true).animate({ width:"-=25px", width:"-=25px" });
});
});
this is just selecting eveything but it still doesnt select the nav.
<td id="navigation">
<?php echo public_navigation($sel_subject, $sel_page); ?>
</td>
I'd like to add .animate jquery to the subjects and pages which are displayed like a list as a side navbar. is there a way to style a query result?
I apologize for my lack of accurate vocabulary. codeybuzz.com is the website if you are having trouble visualizing what I mean, Instead of changing the color of my nav links on a .hover event, i want to animate them on mouseover with jquery. I think doing it with tables might have something to do with it not being selectable, but I dont know how to change them all to divs and not wreck my css styling that i already have in place.
this is the HTML rendered
<td id="navigation">
<ul class="subjects">
<li>About Codey Buzz</li>
<li>No Rubbish, Blog</li>
<li>Top News</li>
</ul>
</td>
I achieved some kind of effect with this, but it isn't very effective.
$(document).ready(function(){
$("ul.subjects > li").hover(function(){
$(this).mouseenter(function() {
$(this).animate({ width: "+=50px" }).stop(true, true);
});
$(this).mouseleave(function() {
$(this).animate({ width: "-=50px" }).stop(true, true);
});
});
});

How to pass variable objects to multiple javascript popup forms

This is my first serious foray into javascript/ajax.
Overview:
I have an index page listing multiple records, each on different rows. For each record I have a link which pops open a small javascript window which contains a symfony form. All goes well, with the exception that I can't figure out how to pass the popup javascript the object Id of each record. Here's what I have:
Starting with the Action:
public function executeTrackReferrals(sfWebRequest $request){
$userId = $this->getUser()->getId();
$this->pager = new sfDoctrinePager('referral', sfConfig::get('app_pager'));
$this->pager->setQuery(Doctrine_Core::getTable('Referral_submissions')->getUsersSubmissions($userId));
$this->pager->setPage($request->getParameter('page', 1));
$this->pager->init();}
Main index page:
<?php
include_partial('<a bunch of other includes >');
include_partial('referral/rtsIndex', array('pager' => $pager));
?>
_rtsIndex partial:
<table>
<?php foreach ($pager->getResults() as $r => $referral): ?>
<?php
$referralObject = Doctrine_Core::getTable('referral')->getReferralObjectById($referral->getId());
$submissionObject = Doctrine_Core::getTable('referral_submissions')->getObjectByReferralId($referralObject->getId());
?>
<TR VALIGN=TOP>
<td WIDTH=10% ALIGN="center" class="_7">
<P ALIGN=CENTER>
<script type='text/javascript'>
$('.popup_changestatus').click(function(){
// put the row id into the hidden field in the popup
var rowId = $(this).parent().find('span.row_id').html();
$('test').val(rowId);
fg_popup_form("fg_formContainer","fg_form_InnerContainer","fg_backgroundpopup");
return false;
});
</script>
<a href="#" class="popup_changestatus">
<?php echo utilities::getStatusCode($submissionObject->getCandidateStatus()); ?>
</a>
<span class="row_id" style="display: none">
<?php echo $referral->getId() ?>
</span>
</P>
</td>
</TR>
</table>
the Javascript popup form code mentioned above, includes this line:
<?php include_partial('referral/changeStatusCodeForm'); ?>
The above line renders the actual symfony form:
_changeStatusCodeForm partial:
<?php
$object = new referral_submissionsForm(<this is where I need to pass an ID for each popup form>);
echo $object;
?>
Can anyone steer me in the right direction?
If interested in the actual javascript code, it's a pretty nifty open source popup:
http://www.html-form-guide.com/contact-form/simple-modal-popup-contact-form.html
EDIT:
Here is the contents of contactform-code.php:
<script type='text/javascript' src='/project/misc/simple-popup-form-1/scripts/gen_validatorv31.js'></script>
<script type='text/javascript' src='/project/misc/simple-popup-form-1/scripts/fg_ajax.js'></script>
<script type='text/javascript' src='/project/misc/simple-popup-form-1/scripts/fg_moveable_popup.js'></script>
<script type='text/javascript' src='/project/misc/simple-popup-form-1/scripts/fg_form_submitter.js'></script>
<div id='fg_formContainer'>
<div id="fg_container_header">
<div id="fg_box_Title">Change Status</div>
<div id="fg_box_Close">Close(X)</div>
</div>
<div id="fg_form_InnerContainer">
<form id='contactus' action='javascript:fg_submit_form()' method='post' accept-charset='UTF-8'>
<input type='hidden' name='submitted' id='submitted' value='1'/>
<input type='hidden' name='<?php echo $formproc->GetFormIDInputName(); ?>' value='<?php echo $formproc->GetFormIDInputValue(); ?>'/>
<input type='text' class='spmhidip' name='<?php echo $formproc->GetSpamTrapInputName(); ?>' />
<div class='short_explanation'>* required fields</div>
<div id='fg_server_errors' class='error'></div>
<div class='container'>
<?php
// $form = new referral_submissionsForm();
include_partial('referral/changeStatusCodeForm');
?>
</form>
</div>
</div>
First, you shouldn't directly use Doctrine_Core into your model. The best way here, is to make a leftJoin on your 2 tables when you pass the query to the pager. Then, in your template, you just fetch the relation (like $object->getRelation()).
Regarding to your problem, you should pass the ID when building the <div id='fg_formContainer'> since it's the content of your popup. The part come from this file: contactform-code.php.
Show us where do you build this div and you will have the place where you have to pass the id.
Edit:
Well, I finally get your problem. You have one popup define on your page that can be called on each click from each row. And you want to know how to pass the row id to the global popup.
This can be done in javascript. Instead of :
<a href='javascript:fg_popup_form("fg_formContainer","fg_form_InnerContainer","fg_backgroundpopup" );'>
<?php echo utilities::getStatusCode($submissionObject->getCandidateStatus()); ?>
</a>
You can better use :
<a href="#" class="popup_contact">
<?php echo utilities::getStatusCode($submissionObject->getCandidateStatus()); ?>
</a>
<!-- use this hidden span to put the row id, to be able to retrieve it using jQuery -->
<span class="row_id" style="display: none">
<?php echo $referral->getId() ?>
</span>
And then, define an action using jQuery (for example):
$('.popup_contact').click(function() {
// put the row id into the hidden field in the popup
var rowId = $(this).parent().find('span.row_id').html();
$('#submitted').val(rowId);
fg_popup_form("fg_formContainer", "fg_form_InnerContainer", "fg_backgroundpopup");
return false;
})

Categories