I am struggling with my custom Javascript / Jquery code.
My code currently takes foldername, imagename, url dynamically from a PHP variable and passed to a function slideShow().
The following code works but shows a blank screen at the start and after the first cycle of images is completed. I understand that if all the images need to be loaded before they can be displayed, there will be a slight delay. Watch the cycle of the images, after cycling 7-8 times, the pages goes blank for 5 seconds before displaying again.
Working copy of the page is here http://tinyurl.com/8yqwvqs
<script type="text/javascript">
function RefreshPage(Period)
{
setTimeout("location.reload(true);", Period);
}
function slideShow(images,path,imageName,lnkUrl,sysFile,tim)
{
imName=imageName.split(",");
urlLink=lnkUrl.split(",");
image=images.split("|");
sysFile1=sysFile.split(",")
var i=0;
l=0;
arrLen=image.length-1
var val=0;
for(i=0;i<image.length-1;i++)
{
(function(i) {
setTimeout(function() {
//alert(time);
var num_of_cat = 4;
var myArr = new Array();
var temp=0;
if(i>=arrLen)
{
imName[3] = imName[3].replace('_',' ');
myArr[1] = '<!--<marquee behavior="slide" scrollamount="10">--><img src="'+path+sysFile1[3]+'" border="0" width="200" height="200"><br><b>'+imName[3]+'</b><!--</marquee>-->';
}
else
{
imName[i] = imName[i].replace('_',' ');
myArr[0] = '<!--<marquee behavior="slide" scrollamount="10">--><img src="'+path+sysFile1[i]+'" border="0" width="200" height="200"><br><b>'+imName[i]+'</b><!--</marquee>-->';
//}
}
if(i+1>=arrLen)
{
imName[2] = imName[2].replace('_',' ');
myArr[1] = '<!--<marquee behavior="slide" scrollamount="10">--><img src="'+path+sysFile1[2]+'" border="0" width="200" height="200"><br><b>'+imName[2]+'</b><!--</marquee>-->';
}
else
{
imName[i+1] = imName[i+1].replace('_',' ');
myArr[1] = '<!--<marquee behavior="slide" scrollamount="10">--><img src="'+path+sysFile1[i+1]+'" border="0" width="200" height="200"><br><b>'+imName[i+1]+'</b><!--</marquee>-->';
//}
}
if(i+2>=arrLen)
{
imName[1] = imName[1].replace('_',' ');
myArr[2] = '<!--<marquee behavior="slide" scrollamount="10">--><img src="'+path+sysFile1[1]+'" border="0" width="200" height="200"><br><b>'+imName[1]+'</b><!--</marquee>-->';
}
else
{
imName[i+2] = imName[i+2].replace('_',' ');
myArr[2] = '<!--<marquee behavior="slide" scrollamount="10">--><img src="'+path+sysFile1[i+2]+'" border="0" width="200" height="200"><br><b>'+imName[i+2]+'</b><!--</marquee>-->';
//}
}
if(i+3>=arrLen)
{
imName[0] = imName[0].replace('_',' ');
myArr[3] = '<!--<marquee behavior="slide" scrollamount="10">--><img src="'+path+sysFile1[0]+'" border="0" width="200" height="200"><br><b>'+imName[0]+'</b><!--</marquee>-->';
}
else
{
imName[i+3] = imName[i+3].replace('_',' ');
myArr[3] = '<!--<marquee behavior="slide" scrollamount="10">--><img src="'+path+sysFile1[i+3]+'" border="0" width="200" height="200"><br><b>'+imName[i+3]+'</b><!--</marquee>-->';
//}
}
for(p=0;p<myArr.length;p++)
{
$('#place'+p).html(myArr[p]);
}
},i*6000);
})(i);
l=l+1;
}
var li;
li=arrLen+"0";
li=li-15;
RefreshPage(li*750);
}
function clock(testArr){
var myArr1=new Array();
myArr1 = shuffle(testArr);
document.getElementById('place0').innerHTML = myArr1[0];
document.getElementById('place1').innerHTML = myArr1[1];
document.getElementById('place2').innerHTML = myArr1[2];
document.getElementById('place3').innerHTML = myArr1[3];
}
slideShow('a.jpg|b.jpg|giftbasketcategory.jpg|homecategory.jpg|img_4903.jpg|kd-vwb-1.jpg|links.jpg|picnicpal-stackeddisplay2.jpg|pictures.jpg|siblingcategorycookie.jpg|weddingsketch.jpg|wooden-bowls.jpg|','./retailers/','Notecards ,Kids__,Baby Gifts ,Wedding Gifts,Wooden Bowls ,Home,Gift_Baskets,','http://abc.com/test.asp?Cat=1818,http://abc.com/test.asp?Cat=1822,http://abc.com/test.asp?Cat=1821,http://abc.com/test.asp?Cat=1819,http://abc.com/test.asp?Cat=1820,http://abc.com/test.asp?Cat=1823,http://abc.com/test.asp?Cat=1824,','IMG_4903.JPG,SiblingCategoryCookie.jpg,PicnicPal-StackedDisplay2.jpg,WeddingSketch.JPG,wooden-bowls.jpg,HomeCategory.JPG,GiftBasketCategory.JPG,',100);
</script>
<table border="0" width="435px" bgcolor="#ECECEC">
<tr>
<td>
</td>
<td style="border:none; text-align:center">
<table >
<tr>
<td>
<div style="width:200px; float:left; text-align:center; padding-left:7px;" id='place0'></div>
<div style="width:200px; float:left; text-align:center; padding-left:7px;" id="place1"></div>
</td>
</tr>
<tr><td><div style="width:200px; float:left; text-align:center; padding-left:7px;" id="place2"></div>
<div style="width:200px; float:left; text-align:center; padding-left:7px;" id="place3"></div></td></tr></table>
</td>
<td>
</td>
</tr>
</table>
Have you tried calling slidehow onLoad on the client side?
http://api.jquery.com/ready/
In the case above:
$(document).ready(function() {
document.slideShow(params);
});
This will avoid all the timeouts messing up with other Javascript files from being fetched/loaded/executed.
Related
I have two tables in my webpage, each being populated with a php while loop.
My first table gets all its data outputted but my second while loop only outputs as many fields as the first one.
My second while loop is not nested within the other one, they are both independent from each other.
When i check the console I see that my second while loops seems to have outputted my data but when I click on my button to display the entire column, only 3 values appear instead of all of them
This is what is shown when I click on TEAM TASK
https://imgur.com/4FCu1dX
This is what is shown when I click on MY TASK
https://imgur.com/q1F6sgx
I also noticed that whether I click on MYTASK or TEAM TASK their are two rows from MYTASK that are always shown.
I Initially had both while loops within the same table but then moved them to each fill there own table but this issue still occurs.
<table border='0' style="float:left; width:20%; height: 500px; border-radius: 5px; display: block;" bgcolor="#2B4353">
<thead>
<tr>
<td bgcolor="#2B4353" border="0" valign="top" align="right">
<div class="messages-header-my" onclick="myTasks()"><p id="myTasks">MY TASKS</p></div></td>
</tr>
</thead>
<tbody>
<?php
while($row8 = mysqli_fetch_array($TableMY)){ $task1234=$row8[1];
?>
<tr id="my" style="display: block;" onclick="myTaskView('<?php echo $task1234?>')"><td bgcolor="#2B4353" border="0" valign="top" colspan="3"><p
<?php if ($row8[0]=='HIGH')
{$statuscss= 'taskHigh';}
elseif ($row8[0]== 'MEDIUM')
{$statuscss= 'taskMedium ';}
else{ $statuscss= 'taskLow';}
echo 'class="',$statuscss,'"';?> style="margin-left: 30px;">OD_<?php echo $task1234?></p></td></tr>
<?php }?>
</tbody>
</table>
<table border='0' style="float:left; width:20%; height: 500px; border-radius: 5px; display: block;" bgcolor="#2B4353">
<thead>
<tr>
<td bgcolor="#2B4353" border="0" valign="top" align="right">
<div class="messages-header-team" onclick="teamTasks()"><p id="teamTasks">TEAM TASKS</p></div></td>
</tr>
</thead>
<tbody>
<?php
while($row8 = mysqli_fetch_array($TableTeam)){ $task1234=$row8[1];
?>
<tr id="team" style="display:none;" onclick="myTaskView('<?php echo $task1234?>')"><td bgcolor="#2B4353" border="0" valign="top" colspan="3"><p
<?php if ($row8[0]=='HIGH')
{$statuscss= 'taskHigh';}
elseif ($row8[0]== 'MEDIUM')
{$statuscss= 'taskMedium ';}
else{ $statuscss= 'taskLow';}
echo 'class="',$statuscss,'"';?> style="margin-left: 30px;">OD_<?php echo $task1234?></p></td></tr>
<?php }?>
</tbody>
</table>
My php
require('server.php');
session_start();
$email=$_SESSION['email'];
$sqli="Select URLDomain from Admin.Users where Email = ?";
$stmt =mysqli_prepare($link,$sqli);
mysqli_stmt_bind_param($stmt,"s",$email );
mysqli_stmt_execute($stmt);
$useremail=mysqli_stmt_get_result($stmt);
$row = mysqli_fetch_array($useremail);
$DBdomain=$row[0];
mysqli_select_db($link,"Universe");
$stmt = mysqli_prepare($link,"Select Priority,TaskNumber from Task where urlDomain=?");
mysqli_stmt_bind_param($stmt,"s",$DBdomain );
mysqli_stmt_execute($stmt);
$TableTeam=mysqli_stmt_get_result($stmt);
mysqli_stmt_close($stmt);
mysqli_select_db($link,"Universe");
$stmt = mysqli_prepare($link,"Select Priority,TaskNumber from Task where TaskOwner=?");
mysqli_stmt_bind_param($stmt,"s",$email );
mysqli_stmt_execute($stmt);
$TableMY=mysqli_stmt_get_result($stmt);
mysqli_stmt_close($stmt);
Here is my Javascript
<script>
function messagesTab() {
document.getElementById("task-message").style.display = "block";
}
</script>
<script>
function myTasks() {
document.getElementById("myTasks").style.color = "#1FAC96";
document.getElementById("teamTasks").style.color = "#FFFFFF";
document.getElementById("team").style.display = "none";
document.getElementById("my").style.display = "block";
document.getElementById("messageDisplay").style.display = "block";
document.getElementById("myTaskView").style.display = "none";
}
</script>
<script>
function teamTasks() {
document.getElementById("teamTasks").style.color = "#1FAC96";
document.getElementById("teamTasks").style.underline = "#1FAC96";
document.getElementById("myTasks").style.color = "#FFFFFF";
document.getElementById("team").style.display = "block";
document.getElementById("my").style.display = "none";
document.getElementById("myTaskView").style.display = "none";
document.getElementById("messageDisplay").style.display = "block";
}
</script>
<script>
function myTaskView(Task_Number) {
$.ajax({
url:'messages_select.php',
type:'POST',
data:{Task_Number:Task_Number},
success:function(data){
$('#myTaskView').html(data);
document.getElementById("myTaskView").style.display = 'block';
document.getElementById("messageDisplay").style.display = 'none';
}
});
}
</script>
<script>
var main = function() {
$('form').submit(function(event) {
var $input = $(event.target).find('input');
var comment = $input.val();
if (comment != "") {
var user = '<i class="fas fa-user-circle"></i>';
var userInfo = $(user).text(' '+'nataliekoly#mail.usf.edu'+' | '+'01/31/19'+' | '+'3:45 PM')
var comment = $('<li>').text(comment);
comment.prependTo('#comments');
userInfo.prependTo('#comments');
$input.val("");
}
return false;
});
}
$(document).ready(main);
</script>
IDs need to be unique, you can't have id="my" and id="team" on each row of the table. Use classes instead:
<tr class="my" style="display: block;" onclick="myTaskView('<?php echo $task1234?>')"><td bgcolor="#2B4353" border="0" valign="top" colspan="3"><p
and
<tr class="team" style="display:none;" onclick="myTaskView('<?php echo $task1234?>')"><td bgcolor="#2B4353" border="0" valign="top" colspan="3"><p
Then you need to loop over them:
document.querySelectorAll(".my").forEach(el => el.style.display = "block");
Am just trying to show all the list in the pagination. am using datatable plugin's pagination on my file, pagination is working fine, in the list i have an image that have a function delete on click. in my pagination 1'st five records is shown . and the other five records shown on click next, delete function working properly on 1'st five record when i click on next than delete function stop it's working .
my code:-
<script>
var conf = jQuery.noConflict();
conf(document).ready(function(){
conf(".delete").on( "click", function() {
alert('adfasdfasd');
//alert(conf(this).attr("id"));
custid = conf(this).attr("id");
var r=confirm("Are you sure");
if (r==true)
{
var url = "<?php echo Mage::getBaseUrl();?>turnkey/index/deleteuser/";
conf.ajax({
type:"POST",
url:url,
data: { 'custid':custid},
success: function(msz){
alert(msz);
if(msz=="deleted") {
conf("#hidepro"+custid).hide("slow");
}
else {
//conf("#hidepro"+proid).hide();
alert("product cant be deleted");
}
//console.log("chal hun");
}
});
}
else
{
return false ;
}
});
});
</script>
and the pagination code is :-
<script type="text/javascript" charset="utf-8">
$(document).ready(function() {
$('#example').dataTable();
} );
</script>
<div id="container">
<div id="demo">
<table cellpadding="0" cellspacing="0" border="0" class="display" id="example" width="100%">
<thead>
<tr>
<th>Factory</th>
<th></th>
<th>Contact</th>
<th>URL</th>
<th>Remove</th>
</tr>
</thead>
<tbody>
<?php
foreach( $custemail as $custemail1 ) {
$customer = Mage::getModel("customer/customer");
$customer->setWebsiteId(Mage::app()->getWebsite()->getId());
$customer->loadByEmail($custemail1); //load customer by email id ?>
<tr class="odd gradeX" style=" border-bottom: 1px solid #FF0000;" id = "hidepro<?php echo $customer['entity_id'] ?>">
<td class="bodyText style4" ><a style=" color: #CC3300;float: left;margin-top: 42px !important;text-decoration: underline;" href="<?php echo Mage::getBaseUrl();?>turnkey/index/listuser?id=<?php echo $customer->getEntity_id();?>"><?php echo $customer->getFactory();?></a> </td>
<td class="bodyText style4">
<a href="<?php echo Mage::getBaseUrl();?>turnkey/index/listuser?id=<?php echo $customer->getEntity_id();?>">
<img style=" width:100px;height:100px;margin-bottom:5px ;" src = "http://lab.ghrix.com/turn-key-mart/media/<?php echo $customer->getUserImage();?>"></a>
</td>
<td class="bodyText style4" style="padding-top: 10px;">
<?php echo $customer->getFirstname();?><?php //echo $customer->getUser_address();?><br><?php echo $customer->getmobile();?><br><?php echo $customer->getEmail();?></td>
<td class="bodyText style4" style="float: left;margin-top: 42px !important;" >
<a target="_blank" style="color:#005580;" href="<?php echo $customer->getWebsite();?>"><?php echo $customer->getWebsite();?></a></td>
<td class="bodyText style4"><div style= "cursor:pointer;" class = "delete" id = "<?php echo $customer['entity_id'] ?>"><img width="60px" src="<?php echo $this->getSkinUrl('images/trash.jpg'); ?>"</div></td>
</tr>
<?php }?>
</tbody>
</table>
</div>
</div>
please suggest where mistake is happen.
Without a live example, I can't be sure, but try this:
replace
conf(".delete").on("click", function() ...
with:
conf(document).on("click", ".delete", function() ...
The reason is that conf(".delete") only attaches to elements available at the time the function is run. It might be that your dataTable plugin runs first, removes the extra elements, then the delete binder is run and only works on the first 5. The second method binds to the document, and checks each click to see if it matches the .delete selector. This used to be known as jQuery.live()
in the below code i am searching a data before searching my url will be in coursemaster_site and when i search it will be in coursemaster_site/index1 and when i close the search results the url will be in coursemaster_site /coursemaster_site but i want url to be in coursemaster_site after closing the search results.
controller:coursemaster_site
function index1()
{
$data = array();
$keyword = $this->input->post('keyword');
if($keyword!=""){
$data['results'] = $this->coursemaster_model->search($keyword);
}
$this->load->view('coursemaster_view', $data);
}
view:coursemaster_view
<form action="<?php echo site_url('coursemaster_site/index1');?>" method = "post">
<br/><center>SEARCH:<input type="text" name = "keyword" required/>
<input type="submit" name="submit" id="opn" value = "Search" onClick="hide1('hiddendiv')" class="btn-success btn" /></center>
</form>
<?php
if (isset($_POST['submit'])) { // Here
// Do the search here
if($results){
?> <div id='hideme'>
CLOSE<a href='coursemaster_site' class='close_notification' title='Click to Close'>
<img src="<?php echo base_url('img/close.png'); ?>" width="15" height="15" alt="Close" onClick="hide('hideme')"/>
</a><div style="background:#FFFFFF; width:1000px; height: 540px; position: absolute; left: 20%; top: 35%; margin-left: -100px; margin-top: -120px" id="modal" >
<table class="display2 table table-bordered table-striped" id='results'>
<tr>
<th>course_code</th>
<th>course name</th>
</tr>
<tr><?php
foreach ($results as $row) {
?>
<td><?php echo $row->course_code;?></td>
<td><?php echo $row->course_name;?></td>
</tr>
<?php
}
}else{
echo"<div id='hideme'>
CLOSE<a href='coursemaster_site' class='close_notification' title='Click to Close'>";
echo "<div id='modal' style='background:#FFFFFF; width:1000px; height: 525px; position: absolute; left: 20%; top: 35%; margin-left: -100px; margin-top: -110px'>";
}
echo"no results";
echo'</div>';
echo '</div>'; }
// If closing
?>
</table>
</div></div>
<script>
$('a.modal').bind('click', function(event) {
event.preventDefault();
$('#modal').fadeIn(10);
});
function hide(obj) {
var el = document.getElementById(obj);
el.style.display = 'none';
}
function hide1(obj) {
var el = document.getElementById(obj);
el.style.display = 'none';
}
</script>
Change to:
<div id='hideme'>CLOSE
<a href='/coursemaster_site' class='close_notification' title='Click to Close'>
...
on both places. The leading slash makes the href start from root.
Do the following changes and check if it works or not:
<div id='hideme'>
CLOSE<a href='javascript:void(0);' class='close_notification' title='Click to Close'>";
The issue is that at form submission through ajax the page still reloads, even though the code has been written for it to not refresh the page, but only a certain div tag. It refreshes the div tag successfully.
As far as I can see (I have quintuple checked) the javascript form submission is written correctly as is the div refresh code.
There might be a problem in the php code where the form and the div that refreshes through ajax are present. The php file and the ajax javascript file are below...
Php file: The div gets refreshed by calling GET ajax=1. The form is called "addmonitor" and the div id is "monitor_form" - located around 2/3 down the bottom of the php code:
<?php
if (DIRECTORY_SEPARATOR=='/'){
define('EZMON_C', dirname(__FILE__));
}else{
define('EZMON_C', str_replace("\\", '/', dirname(__FILE__)));
}
require_once(EZMON_C.'/admin/local_config.php');
function mak_pwords($string, $saltkey, $pos=15) {
$stringA = sha1($string);
$salt = md5($saltkey);
$afterstr = substr($stringA, $pos);
$startbeginning = -(strlen($afterstr));
$beforestr = substr($stringA, 0, $startbeginning);
$hex = '/$E'; // fake ending
$salted = $beforestr . $salt . $afterstr . $hex;
return $salted;
}
//Path to location of local_config.php
error_reporting(0);
// resume the existing session, or establish a new one
session_start();
// Check Login
if(!isset($_SESSION['s_username']) && !isset($_SESSION['s_password']))
{
header("Location:index.php");
exit;
}
//$uid = isset($_GET['uid'])?intval($_GET['uid']):0;
// TODO: this is so wrong, but must remain for now. IMPORTANT!!! move this to index.php, where i assume login password checking is performed.
$uid = isset($_GET['uid'])?intval($_GET['uid']):0;
$_SESSION['uid']=$uid;
if(!isset($_GET['page'])){
$page = 1;
}else{
$page = $_GET['page'];
}
// Added by KTHSoft
if (isset($_GET['ajax'])){
$get_items = 'SELECT * FROM servers WHERE user_id=\''.mysql_real_escape_string($uid).'\'';
$get_items_res = mysql_query($get_items) or die(mysql_error( ));
$total_items = mysql_num_rows($get_items_res);
# Define the number of results per page
$max_results = 10;
/* Figure out the limit for the query based
on the current page number. */
$from = (($page * $max_results) - $max_results);
# get only the limited results
$get_limited_items = "SELECT * FROM servers WHERE user_id='".mysql_real_escape_string($uid)."' ORDER BY com_domain ASC LIMIT $from, $max_results";
$get_limited_items_res = mysql_query($get_limited_items) or die(mysql_error( ));
echo '<table><b>Monitors:</b></table>';
echo '<table>';
$turn = "275";
$cookies_defined = False; // Added by Predrag Bradaric (31. March 2011)
while ($items = mysql_fetch_array ($get_limited_items_res))
{
$domain = $items['domain'];
$com_domain = $items['com_domain'];
$port = $items['port'];
$last_time = $items['last_time'];
$last_date = $items['last_date'];
$last_status = $items['last_status'];
$active = $items['active'];
$sid = $items['id'];
if($last_status==1) {
$status = '<td width="10" align="left"><img src="images/rarrow.png" alt="Website Down" title="Website Down" style="margin-top: 2px;"></td>';
}elseif($last_status == 0){
if($active == 1){
if($last_time !=""){
$status = '<td width="10" align="left"><img src="images/garrow.png" alt="Website Up" title="Website Up" style="margin-top: 2px;"></td>';
}else{
$status = '<td width="10" align="left"><img src="images/pause.png" alt="Monitoring not started yet" title="Monitoring not started yet" style="margin-top: 2px;"></td>';
}
$last_updtt = $last_time;
$last_updtd = $last_date;
}
if($active==0){
$status = '<td width="10" align="left"><img src="images/pause.png" alt="Website Not Monitored" title="Website Not Monitored" style="margin-top: 2px;"></td>';
}
}else{
$status = '<td>Unknown</td>';
}
if($port==80){$port_type="HTTP";
}elseif($port==21){$port_type="FTP";
}elseif($port==143){$port_type="IMAP";
}elseif($port==25){$port_type="SMTP";
}elseif($port==5060){$port_type="SIP";
}elseif($port==110){$port_type="POP";
}elseif($port==443){$port_type="HTTPS";
}elseif($port==2082){$port_type="cPanel";
}elseif($port==2086){$port_type="WHM";
}elseif($port==3306){$port_type="MySQL";
}else{$port_type=$port;}
if($last_time==""){
$last_time="Monitoring not started yet";
}
echo '<tr>'.$status
?>
<!-- MODIFIED BY Predrag Bradaric (29. March 2011) -->
<?php
if (!(isset($_GET['donotrefresh']))) {
if (isset($_COOKIE["$com_domain$port"])) {
$cookies_defined = True;
}
?>
<script type="text/javascript">
if (dhtmlwindow.getCookie("<?php echo "$com_domain$port"; ?>")) {
var window_name = "<?php echo "$com_domain$port"; ?>";
<?php echo "$com_domain$port"; ?> = dhtmlwindow.open(window_name, dhtmlwindow.getCookie(window_name).split("~")[4], decodeURIComponent(dhtmlwindow.getCookie(window_name).split("~")[5]), dhtmlwindow.getCookie(window_name).split("~")[6], 'width='+dhtmlwindow.getCookie(window_name).split("~")[2]+',height='+dhtmlwindow.getCookie(window_name).split("~")[3]+',left='+dhtmlwindow.getCookie(window_name).split("~")[0]+',top='+dhtmlwindow.getCookie(window_name).split("~")[1]+',resize=0,scrolling=0', 'recal');
}
// alert(dhtmlwindow.getCookie("<?php echo "$com_domain$port"; ?>"))
</script>
<!-- END OF MODIFICATION (29. March 2011) -->
<?php } ?>
<td> <!--
<?php echo $domain; ?><?php echo ' ' . $port_type; ?> -->
<?php echo $domain; ?><?php echo ' ' . $port_type; ?>
</td>
<?php
# monitor buttons to pause, resume and delete
if ($active == 1)
{
?>
<td align="right" width="25" style="font-size: 11px; color: #666;">
<img src="images/control_pause.png" title="Pause monitor: <?php echo $domain; ?>" alt="Pause monitor: <?php echo $domain; ?>" height="16" width="16" border="0"></td>
<!--
<td align="right" width="25" style="font-size: 11px; color: #666;">
<img src="images/control_pause.png" title="Pause monitor: <?php echo $domain; ?>" alt="Pause monitor: <?php echo $domain; ?>" height="16" width="16" border="0"></td> -->
<?php
}
else if ($active == 0)
{
?>
<td align="right" width="25" style="font-size: 11px; color: #666;">
<img src="images/control_play_blue.png" title="Resume monitor: <?php echo $domain; ?>" alt="Resume monitor: <?php echo $domain; ?>" height="16" width="16" border="0"></td>
<!--
<td align="right" width="25" style="font-size: 11px; color: #666;">
<img src="images/control_play_blue.png" title="Resume monitor: <?php echo $domain; ?>" alt="Resume monitor: <?php echo $domain; ?>" height="16" width="16" border="0"></td> -->
<?php
}
?>
<td align="right" width="18" style="font-size: 11px; color: #666;">
<img src="images/delete.png" title="Delete monitor: <?php echo $domain; ?>" alt="Delete monitor: <?php echo $domain; ?>" height="16" width="16" border="0"></td>
<!--
<td align="right" width="18" style="font-size: 11px; color: #666;">
<img src="images/delete.png" title="Delete monitor: <?php echo $domain; ?>" alt="Delete monitor: <?php echo $domain; ?>" height="16" width="16" border="0"></td> -->
<?php
# set position of windows displaying the graphs
if ($turn == "275")
{
$turn = "730";
}
else if ($turn == "730")
{
$turn = "275";
}
}
echo "</table>";
// MODIFIED BY Predrag Bradaric (31. March 2011)
if (!($cookies_defined) && !(isset($_GET['donotrefresh']))) {
// init dhtml windows from database
// at this point $uid should be valid user id
include("dhtmlretrieve.php");
}
// END OF MODIFICATION (31. March 2011)
# begin page numbers output
# Figure out the total number of pages. Always round up using ceil()
$total_pages = ceil($total_items / $max_results);
# Build Page Number Hyperlinks
echo "<center><font size=\"2\" color=\"#666666\"face=\"Arial, Helvetica, sans-serif\">Pages of your monitors:<br /></font>";
if($page <= 7)
{
$from_linkedpage = 1;
$to_linkedpage = 15;
}
else
{
if($page > $total_pages - 7)
{
$from_linkedpage = $total_pages - 15;
$to_linkedpage = $total_pages;
}
else
{
$from_linkedpage = $page - 7; //15*floor($page / 15)+1;
$to_linkedpage = $page + 7; //$from_linkedpage + 14;
}
}
if ($to_linkedpage > $total_pages)
{
$to_linkedpage = $total_pages;
}
if ($from_linkedpage < 1)
{
$from_linkedpage = 1;
}
// Build Previous Link
if(($from_linkedpage > 1) || ($page > 1))
{
$prev = ($page - 1);
echo '<a onclick="goToPage(' . $prev . ')" href="#"><b>< Previous</b></a> ';
}
for($j = $from_linkedpage; $j <= $to_linkedpage; $j++)
{
if(($page) == $j)
{
echo "$j ";
}
else
{
echo '<a onclick="goToPage(' . $j . ')" href="#">'.$j.'</a> ';
}
}
// Build Next Link
if($page < $total_pages)
{
$next = ($page + 1);
echo ' <a onclick="goToPage(' . $next . ')" href="#"><b>Next ></b></a>';
}
echo "</font></center><br>";
?>
<script type='text/javascript'>
function goToPage(page){
var dataString = 'ajax=1&donotrefresh=1&page=' + page + '&uid=<?php echo $uid;?>';
$.ajax({
type: "GET",
url: "monpanel.php",
data: dataString,
success: function(html_data){
$('#list_monitors').html(html_data);
}
});
}
</script>
<?php
die();
}
// End added by KTHSoft
/* Temporary config.php replacement */
$uname_admin = $setting['uname_admin'];
$pword_admin = $setting['pword_admin'];
$allow_add = $setting['allow_add'];
$mon_int = $setting['mon_int'];
$max_fail = $setting['max_fail'];
$time_out = $setting['time_out'];
$mon_email = $setting['mon_email'];
$do_logging = $setting['do_logging'];
$fully_log = $setting['fully_log'];
$err_check = $setting['err_check'];
$email_override = $setting['email_override'];
$cfg_offset = $setting['cfg_offset'];
$pingIP_host = $setting['pingIP_host'];
$ping_delay = $setting['ping_delay'];
$num_pings = $setting['num_pings'];
$reliable_test_server = $setting['reliable_test_server'];
$reliable_test_server2 = $setting['reliable_test_server2'];
$date_format = $setting['date_format'];
$version = $setting['version'];
/* End Temporary config.php replacement */
error_reporting(0);
$style='';
$uid = isset($_GET['uid'])?intval($_GET['uid']):0;
$title=' - Viewing UserID:'.$uid.' Servers Status';
header("Cache-Control: must-revalidate");
$offset = 60 * 60 * 24 * -1;
$ExpStr = "Expires: " . gmdate("D, d M Y H:i:s", time() + $offset) . " GMT";
header($ExpStr);
include("header.php");
$monthnow = date("m");
$yearnow = date("Y");
/*
# Delete Monitors
if (isset($_GET["act"]) && $_GET["act"] == "delete") {
$del_items="DELETE FROM servers WHERE id='$_GET[sid]' AND user_id='$_GET[uid]'";
mysql_query($del_items) or die(mysql_error( ));
#echo '<script>alert("Monitor Deleted Successfully!")</script>';
}
# Pause Monitors
if (isset($_GET["act"]) && $_GET["act"] == "pause") {
$pause_items="UPDATE servers SET active=0 WHERE id='$_GET[sid]' AND user_id='$_GET[uid]'";
mysql_query($pause_items) or die(mysql_error( ));
#echo '<script>alert("Monitor Paused Successfully!")</script>';
}
# Resume Monitors
if (isset($_GET["act"]) && $_GET["act"] == "resume") {
$resume_items="UPDATE servers SET active=1 WHERE id='$_GET[sid]' AND user_id='$_GET[uid]'";
mysql_query($resume_items) or die(mysql_error( ));
#echo '<script>alert("Monitor Paused Successfully!")</script>';
}
*/
?>
<script type="text/javascript" src="jquery-1.3.2.min.js"></script>
<script type="text/javascript" src="jquery.validate.min.js"></script>
<script type="text/javascript" src="jquery.cookie.min.js"></script>
<link rel="stylesheet" href="windowfiles/dhtmlwindow.css" type="text/css" />
<script type="text/javascript" src="windowfiles/dhtmlwindow.js"></script>
<link rel="stylesheet" href="modalfiles/modal.css" type="text/css" />
<script type="text/javascript" src="modalfiles/modal.js"></script>
<script type="text/javascript" src="validate.js"></script>
<input type="hidden" id="hidUid" value="<?php echo (intval($uid)); ?>"/>
<?php
// Sanitise security addition
if (is_int(intval($uid))){$uid = intval($uid);}else{$uid = 0;}
if ($uid != '')
{
$date_array = getdate();
foreach ($date_array as $key => $val) {$key = $val;}
$mon=$date_array['mon'];
if($mon<10){$mon="0$mon";}
$day=$date_array['mday'];
if($day<10){$day="0$day";}
$year=$date_array['year'];
$hrs=$date_array['hours'];
if($hrs<10){$hrs="0$hrs";}
$min=$date_array['minutes'];
if($min<10){$min="0$min";}
$sec=$date_array['seconds'];
if($sec<10){$sec="0$sec";}
$time="$hrs:$min:$sec";
// date = month/day/year 10/05/2006
if ($setting['date_format'] == 'day/month/year'){
$day_mon_yr = "$day/$mon/$year";
$date = "$day-$mon-$year";
}
if ($setting['date_format'] == 'month/day/year'){
$day_mon_yr = "$mon/$day/$year";
$date = "$mon-$day-$year";
}
if ($setting['date_format'] == 'year/month/day'){
$day_mon_yr = "$year/$mon/$day";
$date = "$year-$mon-$day";
}
echo '<table align="left" valign="top" width="255" style="margin-top: 0px;">';
if(isset($_SESSION['s_username']))
{
echo '<tr><td width="10"> </td><td style="border: 1px solid #666666; background: #fff; padding: 12px;">';
// loop through the monitors the user has and display them in the menu
$get_items = "SELECT * FROM servers WHERE user_id='$uid'";
$get_items_res = mysql_query($get_items) or die(mysql_error( ));
if(isset($_SESSION['s_username']))
{
?>
<script type='text/javascript'>
var dataString = 'ajax=1&page=' + <?php echo $page?> + '&uid=<?php echo $uid;?>';
$.ajax({
type: "GET",
url: "monpanel.php",
data: dataString,
success: function(html_data){
$('#list_monitors').html(html_data);
}
});
</script>
<?php
echo '<div id="list_monitors">';
echo "</div>";
// chaeck if the user logged in is a paid customer
#$get_paid = "SELECT paid FROM servers WHERE user_id='$uid' LIMIT 1";
#$get_paid_res = mysql_query($get_paid) or die(mysql_error( ));
while ($item_paid = mysql_fetch_array ($get_items_res))
{
$paid_array = $item_paid['paid'];
$paid = $paid_array[0];
}
if ($paid == "1")
{
?>
<div id="monitor_form">
<fieldset border="0">
<table align="left">
<form name="addmonitor" action=""> <!-- action="user_add.php" method="POST" -->
<tr>
<td colspan="2"><font color="#666666"><strong>Add new monitor:</strong></font></td>
</tr>
<input type="hidden" name="cemail" id="cemail" value="<?=$_SESSION['s_username']?>" />
<tr>
<td><label for="domain" id="domain_label" style="text-align: left;">Website URL/IP<br>
<font size="1" color="red">without http://www.</font></label></td>
<td valign="top"><input type="text" size="13" name="domain" id="domain" class="text-input" /></td>
</tr>
<tr>
<td><label class="error" for="domain" id="domain_error">Field is required.</label></td>
</tr>
<tr>
<td><label for="com_domain" id="com_domain_label" style="text-align: left;">Monitor Name</label></td>
<td valign="top"><input type="text" size="13" name="com_domain" id="com_domain" class="text-input" /></td>
</tr>
<tr>
<td><label class="error" for="com_domain" id="com_domain_error">Field is required.</label></td>
</tr>
<tr>
<td><label for="port" id="port_label" style="text-align: left;">Port</label></td>
<td valign="top"><select name="port" id="port" class="select-input">
<option value="80" SELECTED>HTTP: 80</option>
<option value="443">HTTPS: 443</option>
<option value="21">FTP: 21</option>
<option value="5060">SIP: 5060</option>
<option value="80">TCP: 80</option>
<option value="5060">UDP: 5060</option>
<option value="143">IMAP: 143</option>
<option value="25">SMTP: 25</option>
<option value="110">POP3: 110</option>
</select></td>
</tr>
<tr>
<input type="hidden" name="active" id="active" value="1" />
<input type="hidden" name="uid" id="uid" value="<?php echo $uid;?>" />
</tr>
<tr>
<td><label for="main" id="main_label" style="text-align: left;">Main<br>
<font size="1" color="red">only one per URL/IP</font></label></td>
<td valign="top"><select name="main" id="main" class="select-input">
<option value="0">No</option>
<option value="1">Yes</option>
</select></td>
</tr>
<tr>
<td><input type="submit" value="Add monitor" name="addserver" class="button" id="addserver_btn" /></td> <!-- name="addserver" -->
</tr>
</form>
</table>
</fieldset>
</div>
<?php
}
else if ($paid == "0")
{
?>
<div id="free">
<fieldset border="0">
<table align="left">
<form name="free" action=""> <!-- action="user_add.php" method="POST" -->
<tr>
<td colspan="2"><font color="#666666"><strong>Add new monitor:</strong></font></td>
</tr>
<tr>
<td><label for="free" id="free" style="text-align: left;">Website URL/IP<br>
<font size="1" color="red">without http://www.</font></label></td>
<td valign="top"><input type="text" size="13" name="free" id="free" class="text-input" /></td>
</tr>
<tr>
<td><label for="free1" id="free1" style="text-align: left;">Monitor Name</label></td>
<td valign="top"><input type="text" size="13" name="free1" id="free1" class="text-input" /></td>
</tr>
<tr>
<td><label for="free2" id="free2" style="text-align: left;">Port</label></td>
<td valign="top"><select name="free2" id="free2" class="select-input">
<option value="80" SELECTED>HTTP: 80</option>
<option value="443">HTTPS: 443</option>
<option value="21">FTP: 21</option>
<option value="5060">SIP: 5060</option>
<option value="80">TCP: 80</option>
<option value="5060">UDP: 5060</option>
<option value="143">IMAP: 143</option>
<option value="25">SMTP: 25</option>
<option value="110">POP3: 110</option>
</select></td>
</tr>
<tr>
<td><label for="free3" id="free3" style="text-align: left;">Main<br>
<font size="1" color="red">only one per URL/IP</font></label></td>
<td valign="top"><select name="free3" id="free3" class="select-input">
<option value="0">No</option>
<option value="1">Yes</option>
</select></td>
</tr>
<tr>
<td><input type="submit" value="Add monitor" name="free4" class="button" id="free4"
onClick="pay=dhtmlmodal.open('pay', 'div', 'paydiv', 'Paid Account', 'width=425px,height=267px,center=1,resize=0,scrolling=0'); return false" /></td> <!-- name="addserver" -->
</tr>
</form>
</table>
</fieldset>
</div>
<div id="paydiv" style="display:none">
<center>
<h4>To monitor more websites subscribe to our advanced service:</h4>
1) You get to set up monitors for an <b>unlimited number of websites</b><br>2) Unlimited alert emails<br>3) Unlimited alert SMS messages<br>4) and much more for only $5 per month...<br><br>
<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_s-xclick">
<input type="hidden" name="hosted_button_id" value="GDTCMF9N56TKG">
<input type="image" src="https://www.paypal.com/en_AU/i/btn/btn_buynowCC_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online.">
<img alt="" border="0" src="https://www.paypal.com/en_AU/i/scr/pixel.gif" width="1" height="1">
</form>
<br><br>
</center>
</div>
<?php
}
echo '<br><table><b>Account:</b></table>';
echo '<table>';
?>
<tr><td><img src="images/user.png" title="Edit Profile" alt="Edit Profile">
Edit Profile<br>
<img src="images/lock.png" title="Change Password" alt="Change Password">
Change Password<br>
<img src="images/monitor_go.png" title="Logout" alt="Logout"> Logout</tr></td></table>
</table>
<?php
}
}
}
else
{
echo '<br /><br /><br /><br /><br /><br /><br /><br /><br /><br />';
echo '<center><strong>Sorry, You have accessed this page improperly and your access has been logged.</strong></center>';
}
include_once('footer.php');
end;
?>
and the javascript file (only the relevant function):
// Exibit no.1
$(function() {
$(".button").click(function() {
// validate and process form here
$('.error').hide();
var domain = $("input#domain").val();
if (domain == "") {
$("label#domain_error").show();
$("input#domain").focus();
return false;
}
var com_domain = $("input#com_domain").val();
if (com_domain == "") {
$("label#com_domain_error").show();
$("input#com_domain").focus();
return false;
}
var cemail = $("input#cemail").val();
var port = $("select#port").val();
var active = $("input#active").val();
var uid = $("input#uid").val();
var main = $("select#main").val();
var dataString = 'cemail='+ cemail + '&domain=' + domain + '&com_domain=' + com_domain + '&active=' + active + '&main=' + main + '&port=' + port;
//alert (dataString);return false;
$.ajax({
type: "POST",
url: "user_add.php",
data: dataString,
success: function() {
$('#monitor_form').append("<div id='message'></div>");
$('#monitor_form form')[0].reset();
$('#message').html("<img id='checkmark' src='images/tick.png' /><b> Monitor sucessfully added!</b>")
.hide()
.fadeIn(500, function() {
$('#message').append("");
});
setTimeout("$('#message').hide().remove();", 6000);
var dataString2 = 'ajax=1&uid=' + uid;
$.ajax({
async: false,
type: "GET",
dataType: "html",
url: "monpanel.php",
data: dataString2,
success: function(html_data){
$('#list_monitors',top.document).html(html_data);
}
});
//document.onkeydown = showDown;
}
});
return false;
});
});
function showDown(evt) {
event = (evt)? evt : ((event)? event : null);
if (evt) {
if (event.keyCode == 8 && (event.srcElement.type!= "text" && event.srcElement.type!= "textarea" && event.srcElement.type!= "password")) {
// When backspace is pressed but not in form element
cancelKey(evt);
}
else if (event.keyCode == 116) {
// When F5 is pressed
cancelKey(evt);
}
else if (event.keyCode == 122) {
// When F11 is pressed
cancelKey(evt);
}
else if (event.ctrlKey && (event.keyCode == 78 || event.keyCode == 82)) {
// When ctrl is pressed with R or N
cancelKey(evt);
}
else if (event.altKey && event.keyCode==37 ) {
// stop Alt left cursor
return false;
}
}
}
function cancelKey(evt) {
if (evt.preventDefault) {
evt.preventDefault();
return false;
}
else {
evt.keyCode = 0;
evt.returnValue = false;
}
}
Thank you for any insight!
Do not forget to prevent the default handler:
<input type="submit" value="Send" onclick="myAjaxFunction(); return false" />
Does $(".button") have it's href set to #? If so, that'll refresh the page. I suggest using something like:
$(".button").click(function(e){
e.preventDefault();
Follow this if you can...
Basically i have an order form (which begins with one row).
<form id="orderform" name"orderForm" action="/secure/delivery-details.html" method="post">
<a id="add">+</a>
<table id="ordertable" width="533" border="0" cellspacing="0" cellpadding="2">
<tbody>
<tr>
<td width="33%">Product Code (e.g 66203)</td>
<td width="33%">Mtrs Required (e.g 10)</td>
<td width="33%">Preview Image</td>
</tr>
<tr class="item">
<td class="prodcode"><input type="text" name="prodcode[]" id="prodcode" /></td>
<td class="meterage"><input type="text" name="meterage[]" id="meterage" /></td>
<td class="imgsample"></td>
</tr>
</tbody>
</table>
<button>Submit</button>
</form>
Notice the link with an ID of "add". When checked this adds a new row to the table with the same ID. Using the code below.
var counter = 0;
//Order Form
$("#add").click(function() {
counter++;
var cln = $('#ordertable tbody>tr:last').clone(true);
// cln.find("[id^='prodcode']").each(function(i, val) {
// val.id = val.id.match(/^([^0-9]+)[0-9]*$/)[1] + "" + counter;
// });
cln.insertAfter('#ordertable tbody>tr:last');
$('#ordertable tbody>tr:last input').val('');
$('td.imgsample:last a').remove();
return false;
});
//Check for image preview
$("#prodcode").blur(function() {
var $this = $(this);
$this
.closest('tr') // find the parent tr
.find('td.imgsample') // find the imgsample in the row
.html( $(this).attr('id')) // update the contents
//.animate({'opacity':1},200);
var imgsample = $this.closest('tr').find('td.imgsample')
$.post('/public/themes/lbd/js/searchimage.php', //this page reads the image code and gives you the image location
{ action: 'searchimage', imgreference: $(this).val() },
function(data) {imgsample.html(data);}
);
});
My PHP in searchimage...
When i currently enter a product code if it is invalid it only puts the productID in td.imsample and i want it to say INVALID CODE
//Find image based on Product Code
function findimage($imageToFind) {
require '../../../../config.php';
$dbh = new PDO(DB_DSN, DB_USER, DB_PASS);
$sql = "SELECT * FROM isproducts WHERE prodCode = ".strtoupper($imageToFind)."";
$stmt = $dbh->query($sql);
$obj = $stmt->fetch(PDO::FETCH_OBJ);
$count = $stmt->rowCount();
if($count > 0) {
$sql2 = "SELECT * FROM imageindex WHERE filename LIKE '".strtoupper($imageToFind)."-%'";
$stmt2 = $dbh->query($sql2);
$obj2 = $stmt2->fetch(PDO::FETCH_OBJ);
echo ($stmt2->rowCount() == 1 ? '<span>'.$obj2->path.'/'.$obj2->filename.'</span> -' : 'No Image Available');
} else {
echo 'Invalid Code';
}
}
//Call Function
findimage($_POST['imgreference']);
try this, can have code errors since I could not test at all:
jQuery Template
HTML:
<script id="template-item" type="text/x-jquery-tmpl">
<tr class="item" id="${id}">
<td class="prodcode"><input type="text" name="prodcode[]" class="prodcode-input" data="${id}" val="" /></td>
<td class="meterage"><input type="text" name="meterage[]" class="meterage-input" val="" /></td>
</tr>
</script>
<form id="orderform" name"orderForm" action="/secure/delivery-details.html" method="post">
+
<table id="ordertable" width="533" border="0" cellspacing="0" cellpadding="2">
<thead>
<tr>
<th width="33%">Product Code (e.g 66203)</th>
<th width="33%">Mtrs Required (e.g 10)</th>
<th width="33%">Preview Image</th>
</tr>
</thead>
<tbody>
</tbody>
<tfoot>
<td class="imgsample"></td>
</tfoot>
</table>
<button>Submit</button>
</form>
JS:
$(function() {
var counter = 0;
//Check for image preview
var blur_event = function(ev) {
var
self = $(this),
imgsample = $("#ordertable tfoot .imgsample");
$(imgsample).html( $(this).class() ); // update the contents
$.post('/public/themes/lbd/js/searchimage.php', //this page reads the image code and gives you the image location
{ action: 'searchimage', imgreference: $(self).val() },
function(data) {
$(imgsample).html(data);
}
);
return false;
};
//Order Form
$("#add").bind("click", function(ev) {
counter++;
var cln = $('#template-item').tmpl({id:"item-"+counter);
// cln.find("[id^='prodcode']").each(function(i, val) {
// val.id = val.id.match(/^([^0-9]+)[0-9]*$/)[1] + "" + counter;
// });
$(cln).find(".prodcode-input").bind("blur", blur_event);
$(cln).appendTo('#ordertable tbody');
return false;
});
});
Your problem is most likely due to the duplicated ID. That makes your HTML document invalid. See my explanation here.