Hi i am retrieving data from database using pagination which i am able to retrieve but i am facing problem that in my pagination next and last button is not working
here is my code
** index.php**
<script type="text/javascript">
function searchboxfun(numRecords, pageNum ) {
$.ajax({
type: "GET",
url: "usersearchboxresult.php?search=" + document.getElementById("UserSearchBox").value,
data: "show="+numRecords+"&pagenum="+pageNum,
cache: false,
beforeSend: function () {
$('#content').html('<img src="loader.gif" alt="" width="24" height="24" style=" padding-left:469px;">');
},
success: function(html) {
$("#RightPaneContainerDiv").html( html );
}
});
return false;
}
function changeDisplayRowCount(numRecords) {
searchboxfun(numRecords, 1);
}
$( document ).ready(function() {
searchboxfun(10, 1);
});
</script>
<form name="myForm" id="Myform" action="#" onsubmit="return searchboxfun(); ">
<input type="text" id="UserSearchBox" name="UserSearchBox" style="width: 95%; margin-top: 15px; margin-left: 2%;" placeholder="Search Box"/>
<div style="float: right; margin-right: 2%; margin-top: 0px;">
<input type="submit" name="Search" value="Search" id="search" onclick='searchboxfun();'>
</div>
</form>
usersearchboxresult.php
<?php
session_start();
?>
<head>
<style>
.hidden { display: none; }
</style>
<link rel="stylesheet" type="text/css" href="styles.css" />
<script language="javascript" src="users.js" type="text/javascript"></script>
<script src="jquery.js"></script>
</head>
<?php
require_once("configure.php");
// Very important to set the page number first.
if (!(isset($_GET['pagenum']))) {
$pagenum = 1;
} else {
$pagenum = $_GET['pagenum'];
}
//Number of results displayed per page by default its 10.
$page_limit = ($_GET["show"] <> "" && is_numeric($_GET["show"]) ) ? $_GET["show"] : 10;
// Get the total number of rows in the table
//$sql = "SELECT * FROM tbl_pagination WHERE 1" ;
$search=$_GET['search'];
$eid=$_SESSION['eid'];
$sql="select * from clientreg where eid=$eid and (mobile like '%$search%' or fname like '%$search%' or service like '%$search%')";
//$select_table = "";
$cnt = mysql_num_rows( mysql_query($sql))or die("There is no record in Database!");
//Calculate the last page based on total number of rows and rows per page.
$last = ceil($cnt/$page_limit);
//this makes sure the page number isn't below one, or more than our maximum pages
if ($pagenum < 1) {
$pagenum = 1;
} elseif ($pagenum > $last) {
$pagenum = $last;
}
$lower_limit = ($pagenum - 1) * $page_limit;
$sql2 = $sql . " limit ". ($lower_limit)." , ". ($page_limit). " ";
$rs = mysql_query($sql2);
?>
<form name="frmUser" method="post" action="">
<div style="width:98%; margin-left:20px;">
<table border="0" cellpadding="10" cellspacing="1" width="100%" class="tblListForm">
<?php
$j=0;
$countleadmodified=array();
$countResult = 0;
while ( $row = mysql_fetch_array($rs) ) {
<tr>
<td><input type="checkbox" name="users[]" class="users" value="<?php echo $row["id"]; ?>" ></td>
<td>✰</td>
<td><?php echo $_SESSION['user'];?></td>
<td><?php echo $row["fname"];?></td>
<td><?php echo $row["lname"];?></td>
<td><?php echo $row["mobile"];?></td>
</tr>
<?php
$j++;
}
?>
</table>
</div>
</form>
<div id="paging">
<div class="height30"></div>
<table width="50%" border="0" cellspacing="0" cellpadding="2" align="center">
<tr>
<td valign="top" align="left">
<label> Rows Limit:
<select name="show" onChange="changeDisplayRowCount(this.value);">
<option value="10" <?php if ($_GET["show"] == 10 || $_GET["show"] == "" ) { echo ' selected="selected"'; } ?> >10</option>
<option value="20" <?php if ($_GET["show"] == 20) { echo ' selected="selected"'; } ?> >20</option>
<option value="30" <?php if ($_GET["show"] == 30) { echo ' selected="selected"'; } ?> >30</option>
</select>
</label>
</td>
<td valign="top" align="center" >
<?php
if ( ($pagenum-1) > 0) {
?>
First
Previous
<?php
}
//Show page links
for($i=1; $i<=$last; $i++) {
$j=1;
if ($i == $j) {
?>
<!--<a href="javascript:void(0);" class="selected" ><?php echo $i ?></a>-->
<?php
} else {
?>
<a href="javascript:void(0);" class="hidden" onclick="displayRecords('<?php echo $page_limit; ?>', '<?php echo $i; ?>');" ><?php echo $i ?></a>
<?php
}
$j++;}
if ( ($pagenum+1) <= $last) {
?>
Next
<?php } if ( ($pagenum) != $last) { ?>
<a href="javascript:void(0);" onclick="displayRecords('<?php echo $page_limit; ?>', '<?php echo $last; ?>');" class="links" >Last</a>
<?php
}
?>
</td>
<td align="right" valign="top">
Page <?php echo $pagenum; ?> of <?php echo $last; ?>
</td>
</tr>
</table>
</div>
here i this code i am able to retrive data from data base but any pagination is not working
where i am wrong how can i achieve my goal
Any help will be appreciated
Related
I have the following code in my program that works perfectly with the WAMP server. But I had to change the WAMP server for XAMPP and I don’t know why it doesn’t execute some parts of the code. There’s also no error message.
The problem is that in the table code <table>, it doesn’t show after the third <tr> or when the 'Toggle' starts. It also doesn’t show the submit button.
I don’t understand why everything works correctly in WAMP but not in XAMPP. Can someone help me see why it fails? Thank you
Project.php
<?php
include_once("Conexion.php");
include_once("functions.php");
ob_start();
$_SESSION['ex_time'] = date('Y-m-d H:i:s');
$list_ex = array();
$result = doSearch($conn);
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" type="text/css" href="styleProject.css">
</head>
<body>
<div id="centered_A">
<form action='' method='post'>
<table id="exercises">
<tr>
<th colspan="3"><h2>Exercises</h2></th>
</tr>
<tr>
<th><h3>Exercise_ID</h3></th>
<th><h3>Title</h3></th>
<th><h3>Difficulty
<form id="difficulty_form" method="get">
<select id="filter" name="filter" onchange="document.getElementById('difficulty_form').submit()">
<option value="All">Todas</option>
<?php
for ($i = 1; $i <= 5; $i++) {
$selected = '';
if (isset($_GET['filter']) && $_GET['filter'] == $i) {
$selected = ' selected';
}
echo "<option value=\"$i\"$selected>$i</option>\n";
}
?>
</select>
</form>
</h3></th>
</tr>
<?php
$order = 1;
$num_ex = 1;
while($row = $result->fetch_assoc())
{
array_push($list_ex, $row["exercise_id"]);
$sql_check_ex = "select * from answers a where a.student_id=".$_SESSION['user_id']." and a.exercise_id_fk=".$row["exercise_id"].";";
$result_check_ex = $conn->query($sql_check_ex);
?>
<tr>
<td><?php echo $num_ex; ?></td>
<!---Click Toggle Exercise-->
<td><a onclick="myFunction(<?php echo $row["exercise_id"] ?>)" role="button" class="btn" target="_blank" ><?php echo $row["title"]; ?></a>
</td>
<td><?php echo $row["difficulty"]; ?></td>
</tr>
<!--- Toggle --->
<tr id="toggle<?php echo $row["exercise_id"] ?>" style="display:none">
<td colspan="3">
<?php
$sql = "SELECT * FROM exercises WHERE exercise_id='".$row["exercise_id"]."'";
$result_ej = $conn->query($sql);
$row_ej = $result_ej->fetch_assoc();
?>
<p><?php $row["exercise_id"] ?> <?php echo $row["text"]?></p>
<br><!--- Radio Button --->
<?php
if ($row["type"] == 0) {
$ansarray = explode("\n", $row["image_path"]);
$randomans = [];
for($i=0; $i<count($ansarray); $i++) {
$a = array($i+1, $ansarray[$i]);
array_push($randomans, $a);
}
shuffle($randomans);
for($i=0; $i<count($randomans); $i++) {
echo "<div class=\"radio\" style=\"text-align:left; display:flex; vertical-align: baseline;\">";
echo "<input type=\"radio\" style=\"margin-top: 8px; cursor:pointer;\" name=\"choice".$row["exercise_id"]."\" value= \"".$randomans[$i][0]."\" />".$randomans[$i][1]."<br>";
echo "</div>";
}
echo "<input type=\"text\" name=\"choicetext".$row["exercise_id"]."\" value='multi' style=\"display:none;\">";
} else {
?>
<input type="radio" style="margin-top: 8px" name="choice<?php echo $row["exercise_id"] ?>" value= "0" checked="checked" style="display:none;" />
<?php
}
?>
<br>
<!--- Select level --->
<p2>Select difficulty level:</p2>
<select name="choose<?php echo $row["exercise_id"] ?>" id="choose<?php echo $row["exercise_id"] ?>">>
<option value="1" <?php if($row["difficulty"]=="1") { echo "selected"; } ?> >1</option>
<option value="2" <?php if($row["difficulty"]=="2") { echo "selected"; } ?> >2</option>
</select>
</td>
</tr><!---Finish Toggle --->
<?php
$order++;
$num_ex++;
}
?>
</table>
<br><!---Submit Button-->
<input class="buttonSubmit" type="submit" name="submit_proj_ex" value="Submit">
</form>
<script>
function myFunction(ejer_id) {
var x = document.getElementById("toggle" + ejer_id);
if (x.style.display === "none") {
x.style.display = "table-row";
} else {
x.style.display = "none";
}
}
</script>
</div>
</body>
<?php
if (isset($_POST['submit_proj_ex'])) {
include_once("store_answers.php");
header('location: Results.php');
}
?>
</html>
functions.php
<?php
function doSearch($conn, $fields = "*") {
$sql = "SELECT $fields FROM exercises, ex_tag, tags where exercise_id = exercise_id_fk and tag_id = tag_id_fk";
if (isset($_GET['filter']) && $_GET['filter'] !== 'All') {
$filter = (int) trim($_GET['filter']);
$sql .= " and exercises.difficulty = '$filter'";
}
if (!empty($_SESSION['tags_array'])) {
$sql .= " and (";
foreach ($_SESSION['tags_array'] as $tagId)
$sql .= 'tag_id = ' . $tagId . ' or ';
$sql .= "tag_id = -1)";
}
$sql .= ' group by exercise_id_fk';
return $conn->query($sql);
}
?>
Run phpinfo() in both WAMP and XAMP. I'm not certain what your issue is, but if it works in one and not the other, perhaps they are using different versions of php. If this is the case, you will need to use the same version of php in your XAMP as you were using in WAMP, or go through your code and try to figure out how to convert your code, such that it works correctly with the version on your XAMP. The former is probably the path of least resistance.
Basically, I have a list of categories that I am iterating form mysqli
<div style="width:20%; float:left;">
<h3>Categories</h3>
<?php while($categories = $resultproductcategories->fetch_assoc()){?>
<div class="rows">
<input type="button" name="<?php echo $categories['id'] ?>" value="<?php echo $categories['category?>" />;
</div>
<?php }?>
</div>
Now what I want that if I press any category it should fetch data accordingly there is my code for fetching
$stmtproducts = $mysqli->prepare("SELECT * FROM store_products sp INNER JOIN store_product_categories spc ON sp.product_category=spc.id WHERE sp.store_id=? AND sp.category=? LIMIT $count, 10");
$stmtproducts->bind_param("ii",$_SESSION['storeid'],$_POST['']);
$stmtproducts->execute();
$resultproducts = $stmtproducts->get_result();
$num=$resultproducts->num_rows;
echo $num;
$stmtproducts->close();
I am confused that if there was a specific name of input then I would have gotten it by isset($_POST['name']) but there is no specific name... I cannot think of how to send category to mysql.
<div id="divTransactional" style="width:70%;padding-left:5%; float:left;">
<?php if($num>0) {?>
<table class="table table-responsive table-hover" id="tableProducts">
<h3>Products</h3>
<tbody>
<?php for($i=0;$i<$num;$i++) { $products = $resultproducts->fetch_assoc();//while($products = $resultproducts->fetch_assoc()) {?>
<tr>
<td>Code: <?php echo $products['product_code'];?></td><td>Added On: <?php echo $products['product_date'];?></td>
</tr>
<tr>
<td>Name: <?php echo $products['product_name'];?></td>
</tr>
<tr>
<td>Category: <?php echo $products['category'];?></td>
</tr>
<tr>
<td>Description: <?php echo $products['product_desc'];?></td>
</tr>
<tr>
<td>Price: <?php echo $products['product_price'];?></td><td>Discount: <?php echo $products['product_discount'];?></td>
</tr>
<tr style="width:100px; height:100px;">
<td><img src="../../uploads/store/products/<?php echo $products['product_image1'];?>" style="width:100px; height:100px;"/></td>
<td><img src="../../uploads/store/products/<?php echo $products['product_image2'];?>" style="width:100px; height:100px;"/></td>
<td><img src="../../uploads/store/products/<?php echo $products['product_image3'];?>" style="width:100px; height:100px;"/></td>
<td><img src="../../uploads/store/products/<?php echo $products['product_image4'];?>" style="width:100px; height:100px;"/></td>
</tr>
<?php }?>
</tbody>
<?php if($num >= 10) { ?>
Next
<?php } ?>
<?php $prev = $count - 10;
if ($prev >= 0){?>
Previous
<?php }?>
</table>
<?php if($num >= 10) { ?>
Next
<?php } ?>
<?php $prev = $count - 10;
if ($prev >= 0){?>
Previous
<?php }?>
<?php } ?>
</div>
I would suggest using Ajax to call the server with an Id in parameters.
You need to add a class to your buttons and you do need to link a JS file and JQuery. here's an example.
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
<script src="path/to/your/file.js"></script>
<div style="width:20%; float:left;">
<h3>Categories</h3>
<?php while($categories = $resultproductcategories->fetch_assoc()){?>
<div class="rows">
<input type="button" name="<?php echo $categories['id'] ?>" value="<?php echo $categories['category']?>" class="btnCategory"/>;
</div>
<?php }?>
And then, using ajax you can call your php file that returns the value you need to fetch from your database.
$(document).ready(function() {
$('.btnCategory').on('click', function(){
var id = $this.attr('name');
$.ajax({
url: 'path/to/your/file.php',
method: "GET",
data: {category_id: id},
success: function(data) {
//This is the data fetch from the server
console.log(data);
},
error: function(err) {
console.error('An error occurred : ' + err);
}
});
});
});
And then, when your PHP file receive the parameter $_GET['category_id'] you call your database.
<?php
if(isset($_GET['category_id'])){
//An id was post in the url.
$stmtproducts = $mysqli->prepare("SELECT * FROM store_products sp INNER JOIN store_product_categories spc ON sp.product_category=spc.id WHERE sp.store_id=? AND sp.category=? LIMIT $count, 10");
$stmtproducts->bind_param("ii",$_SESSION['storeid'],$_POST['']);
$stmtproducts->execute();
$resultproducts = $stmtproducts->get_result();
$num=$resultproducts->num_rows;
$stmtproducts->close();
$result = array('row_count' => $num, 'result' => $resultproducts);
echo json_encode($result);
}
And then you return a json array of your result. That's what I would do.
Hope it helps !
Nic
You asked for a demo, here it is .
<?php
if(isset($_GET['category_id'])){
//An id was post in the url.
$stmtproducts = $mysqli->prepare("SELECT * FROM store_products sp INNER JOIN store_product_categories spc ON sp.product_category=spc.id WHERE sp.store_id=? AND sp.category=? LIMIT $count, 10");
$stmtproducts->bind_param("ii",$_SESSION['storeid'],$_POST['']);
$stmtproducts->execute();
$resultproducts = $stmtproducts->get_result();
$num=$resultproducts->num_rows;
$stmtproducts->close();
$result = array('row_count' => $num, 'result' => $resultproducts);
echo json_encode($result);
}
?>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
<div style="width:20%; float:left;">
<h3>Categories</h3>
<?php while($categories = $resultproductcategories->fetch_assoc()){?>
<div class="rows">
<input type="button" name="<?php echo $categories['id'] ?>" value="<?php echo $categories['category']?>" class="btnCategory"/>;
</div>
<?php }?>
</div>
<script>
$(document).ready(function() {
$('.btnCategory').on('click', function(){
var id = $this.attr('name');
$.ajax({
method: "GET",
data: {category_id: id},
success: function(data) {
//This is the data fetch from the server
console.log(data);
},
error: function(err) {
console.error('An error occurred : ' + err);
}
});
});
});
</script>
On a page I have 8500 Employees shown in table data in the form of <tr> and <td>.
The Name of the Employees shown with a checkbox in front of each name of employee.
When I click on checkboxes the I insert the employees data (Employee Name and Employee Id) session.
Everything is working fine but the problem is when I click on check All checkbox then all the employees checkboxes are selected then there is a button named as "View Selected". On the click of this button I want to all the selected employees. When user click on this button a new child window will be opened with selected employee data in the form table row and data.
I am doing this but using session which I have created on the click of employees checkboxes.
Everything is working on Mozilla Firefox but when I check this of Google Chrome then it is not working and I am getting the browser message KillPages or Wait. The loader image of Chrome is shown but data is not loading.
My new child window page code is this where I am reading the session and running the for-each loop to print the data in the form of table data.
<?php require_once("../../includes/global.php");
$sessionName = rq('sessionName');
$employees = $session->read($sessionName);
?>
<script type="text/javascript" src="<?php echo SITEURL_PAGE; ?
>configuration/js/attendancePolicy.js"></script>
<div style="width: 100%;">
<?php if(strpos($sessionName, 'location') !== false) {?>
<h3 style="padding-left:10px;">View <?php echo LOCATION_DISPLAY_NAME?>s</h3>
<?php } else {?>
<h3 style="padding-left:10px;">View <?php echo
us(substr(str_replace('ot_','',$sessionName), 0, -3))?></h3>
<?php }?>
<?php
$totalEmployees = $session->check($sessionName) ? (int)count($session->read($sessionName)) : 0;
?>
<form id="updateEmployeesForm" name="updateEmployeesForm" method="post" action="saveAttendancePolicy.php">
<input type="hidden" name="hidAction" value="addNewPolicy_step3" />
<input type="hidden" name="sessionName" id="sessionName" value="<?php echo $sessionName?>" />
<?php
$styleTab = '';
$style='';
if($totalEmployees > 30){
$styleTab = 'border-bottom: none;';
$style = 'overflow:auto; height: 230px !important; border-bottom: 4px solid #2C90D3;';
}
//for over time policy only
$functionSuffix = '';
if($sessionName == 'ot_locations_cb' || $sessionName == 'ot_divisions_cb' || $sessionName == 'ot_departments_cb' || $sessionName == 'ot_employees_cb') {
$functionSuffix = 'overTimePolicy';
}
$where = rq('where');
$employeeLoadPage = ($sessionName == 'ot_employees_cb')?'otpolicy_ajax':'';
if(stripos($sessionName, 'employee') > -1) {
$js = "closeClildWindow('', 'employeeDiv', 'yes','".$employeeLoadPage."');";
} else if(stripos($sessionName, 'location') > -1) {
$js = "searchPolicySpecificNew('', 'locations', 'locationDiv', {'session':'yes'},'".$functionSuffix."'); updateChildPolicyNew('".$sessionName."', 'yes','".$functionSuffix."');";
} else if(stripos($sessionName, 'division') > -1) {
$js = "searchPolicySpecificNew('', 'divisions', 'divisionDiv', {'session':'yes'},'".$functionSuffix."'); updateChildDepartmentPolicyNew('".$sessionName."', 'locations_cb', 'yes','".$functionSuffix."');";
} else if(stripos($sessionName, 'department') > -1) {
$js = "searchPolicySpecificNew('', 'departments', 'departmentDiv', {'session':'yes'},'".$functionSuffix."'); updateChildjobTitlePolicy('".$sessionName."', 'divisions_cb', 'locations_cb', '','".$functionSuffix."');";
}
if($where == 'viewEmp') {
if($sessionName == 'ot_employees_cb') {
$js="getSelectedEmployeesNew('OT');";
} else {
$js="getSelectedEmployeesNew();";
}
}
?>
<div class="totalRecord" style="float:right; width:99%;text-align:right; margin-top: 5px;">
<label>Total Record(s) :<?php echo $totalEmployees ?></label>
</div>
<div style="margin: 0 2% 0 2%; width: 96%;" class="div_row">
<table cellpadding="0" border="0" cellspacing="0" width="100%" class="bdrtable" style="border-bottom: 0px;">
<thead>
<tr>
<th align="left" scope="col" colspan="5"> <input type="checkbox" name="viewCheckAllName" id="viewCheckAllName" <?php if($totalEmployees > 0) {?> checked="checked"<?php }?> class="class_parent_pop" onClick="sessionCheckBox('class_parent_pop', '<?php echo $sessionName?>_pop', 'parent', this);" />
Check All </th>
</tr>
</thead>
</table>
</div>
<div style="margin-bottom: 2%; margin-left: 2%; margin-right: 2%; width:96%;<?php echo $style;?>" class="div_row">
<table cellpadding="0" border="0" cellspacing="0" width="100%" class="bdrtable" style="<?php echo $styleTab?>">
<?php if($totalEmployees > 0) { ?>
<tr>
<?php $i=1;
foreach($employees as $key=>$employeeArr) {
?>
<td align="left" width="33%"><?php echo $i; ?> </td>
<?php
if($i%3 == 0 && $i != $totalEmployees) {
echo '</tr><tr>';
}
$i++;
}
if($totalEmployees%3 != 0) {
for ($x=($totalEmployees%3); $x < 3; $x++) {
echo '<td align="left" width="33%"> </td>';
}
}
?>
</tr>
<?php }else{ ?>
<tr>
<td colspan="3" align="center"><?php echo "No Data Found"; ?></td>
</tr>
<?php }?>
</table>
</div>
<div class="clear"></div>
<div class="div_row" style="text-align: right; width: 96%; margin:0 2%;">
<?php if($totalEmployees > 0) {?>
<input type="button" name="updateEmp" id="updateEmp" value="Update" class="submit" onClick="sessionCheckBoxPopupUpdate('<?php echo $sessionName?>_pop', '<?php echo $sessionName?>');<?php echo $js; ?>" />
<?php } ?>
<input type="button" name="cancel" id="cancel" value="Cancel" class="submit" onClick="javascript:window.close();" />
</div>
</form>
It may not be the foreach loop that is slow, 8500 is good number of data to load, you might want to page the results.
Why don't you try the same query using phpmyadmin and see the time taken.
I have some HTML/PHP code in Dreamweaver and for the life of me I cannot figure out the cause of this error. The error reads, "There is a syntax error on line 318. Code hinting may not work until you fix this error." Could someone help? And yes, I know I have terrible commenting practice and variable nomenclature. The code can also be found here
<?php
require $_SERVER['DOCUMENT_ROOT'].'/resources/feeds.php';
require $_SERVER['DOCUMENT_ROOT'].'/resources/mysql.php';
session_start();
if(empty($_SESSION['username']) || $_SESSION['login'] != 'true'){ header("location:/"); }
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<!--
Design by Free CSS Templates
http://www.freecsstemplates.org
Released for free under a Creative Commons Attribution 2.5 License
Name : Vegetables
Description: A two-column, fixed-width design with dark color scheme.
Version : 1.0
Released : 20110416
-->
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<link rel="icon" type="/image/png" href="/resources/favicon.png">
<meta name="keywords" content="" />
<meta name="description" content="" />
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>My Website • Edit Information</title>
<link href="/style.css" rel="stylesheet" type="text/css" media="screen" />
</head>
<body>
<div id="header">
<div id="logo">
<h1>My Website</h1>
This is the best website ever
<p> </p>
</div>
</div>
<!-- end #header -->
<div id="wrapper">
<div id="menu">
<ul>
<li class="current_page_item">Home</li>
<li>Events</li>
<li>Forums</li>
<li>About</li>
<li>Minutes</li>
<li>Documents</li>
<li>Contact Us</li>
</ul>
</div>
<!-- end #menu -->
</div>
<div id="page">
<div id="content">
<div class="post">
<h2 class="title">Edit Information</h2>
<div style="clear: both;"><form action="/admin"><input type="submit" value='Back'/></form></div>
<div style="clear: both;"></div>
<div class="entry">
<SCRIPT language="javascript">
function add() {
x++;
var foo = document.getElementById('my_div');
foo.innerHTML = foo.innerHTML +"<input type='text' name='tg"+x+"' placeholder='name'><br />";
}
function addch() {
y++;
var foo = document.getElementById('my_other_div');
foo.innerHTML = foo.innerHTML +"<input type='text' name='ch"+y+"' placeholder='name'><br />";
}
function addws() {
z++;
var foo = document.getElementById('my_other_other_div');
foo.innerHTML = foo.innerHTML +"<input type='text' name='ws"+z+"' placeholder='workshop name and leaders' style='width: 98%;'><br />";
}
function detect(form) {
if(form.checked) {
window.backUpHtml = document.getElementById('con_div').innerHTML;
document.getElementById('con_div').innerHTML = '';
} else {
document.getElementById('con_div').innerHTML = window.backUpHtml;
window.backUpHtml = '';
}
}
</SCRIPT>
<form name="form1" method="post" action="./"><font color="#FFFFFF">
<table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#00000" style="max-width: 560px;">
<tr>
<td width="10%">Name</td>
<td width="90%"><?php echo "<input name='name' type='text' value='".stripslashes($_POST['name'])."' required='required'/>"; ?><input type="checkbox" onclick="detect(this)" name="isyac" id="isyac" value="yes" <?php if(isset($_POST['isyac'])) { echo "checked='checked'";} ?> /><label for="isyac">YAC Meeting</label></td>
</tr>
<tr>
<td width="10%" style="vertical-align:top;">Description</td>
<td width="90%"><?php echo '<textarea name="desc" rows="5" cols="60" style="resize: vertical;" required="required">'.stripslashes($_POST["desc"]).'</textarea>'; ?></td>
</tr>
<tbody id="con_div">
<!-- START OF CON DIV -->
<tr>
<td width="10%" style="vertical-align:top;">Touchgroup Leaders</td>
<td width="90%">
<?php
$blah = 1;
while(isset($_POST['tg'.$blah])) {
echo '<input type="text" name="tg'.$blah.'" value="'.stripslashes($_POST["tg".$blah]).'" /><br />';
$blah++;
}
$hoo = $blah - 1;
echo "<script language='javascript'> var x = ".$hoo."; </script>";
?>
<div id="my_div"></div>
<input type="button" value="Add" onClick="add()">
</td>
</tr>
<tr>
<td width="10%" style="vertical-align:top;">Chaplains</td>
<td width="90%">
<?php
$blah = 1;
while(isset($_POST['ch'.$blah])) {
echo '<input type="text" name="ch'.$blah.'" value="'.stripslashes($_POST["ch".$blah]).'" /><br />';
$blah++;
}
$hoo = $blah - 1;
echo "<script language='javascript'> var y = ".$hoo."; </script>";
?>
<div id="my_other_div"></div>
<input type="button" value="Add" onClick="addch()">
</td>
</tr>
<tr>
<td width="10%" style="vertical-align:top;">Workshops</td>
<td width="90%">
<?php
$blah = 1;
while(isset($_POST['ws'.$blah])) {
echo '<input type="text" name="ws'.$blah.'" value="'.stripslashes($_POST["ws".$blah]).'" style="width: 98%;"/><br />';
$blah++;
}
$hoo = $blah - 1;
echo "<script language='javascript'> var z = ".$hoo."; </script>";
?>
<div id="my_other_other_div"></div>
<input type="button" value="Add" onClick="addws()">
</td>
</tr>
</tbody>
<!-- END OF CON DIV -->
<tr>
<td width="10%" style="vertical-align:top;">Registration Links</td>
<td width="90%">
<?php echo '<input type="text" name="YouthLink" value="'.stripslashes($_POST['YouthLink']).'"/> Youth Link<br />
<input type="text" name="AdultLink" value="'.stripslashes($_POST['AdultLink']).'"/> Adult Link'; ?>
</td>
</tr>
<tr>
<td width="10%" style="vertical-align:top;">Start Date</td>
<td width="90%">
<select name='startmonth'>
<?php $idk = array("January","February","March","April","May","June","July","August","September","October","November","December");
foreach ($idk as $bob):
if($bob = $_POST['startmonth']) {
echo '<option value="'.$bob.'" selected="selected">'.$bob.'</option>';
} else {
echo '<option value="'.$bob.'">'.$bob.'</option>';
}
endforeach;
?>
</select>
<select name="startday">
<?php
$x = 1;
while($x <= 31) {
if((int)$_POST['startday'] == $x) {
echo "<option value='".$x."' selected='selected'>".$x."</option>";
} else {
echo "<option value='".$x."'>".$x."</option>";
}
$x++;
}
?>
</select>
<select name="startyear">
<?php $date = getdate();
for($x = 0;$x < 3;$x++) {
$y = (int)$date['year']+$x;
if($y == $_POST['startyear']) {
echo "<option value='".$y."' selected='selected'>".$y."</option>";
} else {
echo "<option value='".$y."'>".$y."</option>";
}
}
?>
</select>
</td>
</tr>
<tr>
<td width="10%" style="vertical-align:top;">End Date</td>
<td width="90%">
<select name='endmonth'>
<?php $idk = array("January","February","March","April","May","June","July","August","September","October","November","December");
foreach ($idk as $bob):
if($bob = $_POST['endmonth']) {
echo '<option value="'.$bob.'" selected="selected">'.$bob.'</option>';
} else {
echo '<option value="'.$bob.'">'.$bob.'</option>';
}
endforeach;
?>
</select>
<select name="endday">
<?php
$x = 1;
while($x <= 31) {
if((int)$_POST['endday'] < $x) {
echo "<option value='".$x."'>".$x."</option>";
} else if((int)$_POST['endday'] == $x) {
echo "<option value='".$x."' selected='selected'>".$x."</option>";
} else if((int)$_POST['endday'] > $x) {
echo "<option value='".$x."'>".$x."</option>";
}
$x++;
}
?>
</select>
<select name="endyear">
<?php $date = getdate();
for($x = 0;$x < 3;$x++) {
$y = (int)$date['year']+$x;
if($y == $_POST['endyear']) {
echo "<option value='".$y."' selected='selected'>".$y."</option>";
} else {
echo "<option value='".$y."'>".$y."</option>";
}
}
?>
</select>
</td>
</tr>
<tr>
<td width="10%" style="vertical-align:top;">Location</td>
<td width="90%">
<?php echo '<input type="text" name="location" value="'.stripslashes($_POST['location']).'" required="required"/>'; ?>
</td>
</tr>
<tr>
<td width="90%"></td>
<td width="10%">
<input type="hidden" name="blah" value="blah"/>
<input type="submit" name="woohoo" value="Save" align="right"/>
</td>
</table>
</form>
<?php if(isset($_POST['isyac'])) {
echo "<script language='javascript'>window.backUpHtml = document.getElementById('con_div').innerHTML;
document.getElementById('con_div').innerHTML = '';</script>"; ?>
}
</div>
</div>
<div style="clear: both;"> </div>
</div>
<!-- end #content -->
<div id="sidebar">
<?php include($_SERVER['DOCUMENT_ROOT'].'/resources/side.php'); ?>
</div>
<!-- end #sidebar -->
<div style="clear: both;"> </div>
</div>
<!-- end #page -->
<div id="footer-menu">
<ul>
<li class="current_page_item">Home</li>
<li>Events</li>
<li>Forums</li>
<li>About</li>
<li>Minutes</li>
<li>Documents</li>
<li>Contact Us</li>
</ul>
</div>
<div id="footer">
<p>Copyright © <?php $date = getdate(); echo $date['year']; ?> My Website. All rights reserved.</p>
</div>
<!-- end #footer -->
</body>
</html>
Your problem comes from this bit of code:
<?php if(isset($_POST['isyac'])) {
echo "<script language='javascript'>window.backUpHtml = document.getElementById('con_div').innerHTML;
document.getElementById('con_div').innerHTML = '';</script>"; ?>
}
the closing brace } needs to be inside the php tags (before the ?>)
I just glanced over your code and I would say this is probably it:
</form>
<?php if(isset($_POST['isyac'])) {
echo "<script language='javascript'>window.backUpHtml = document.getElementById('con_div').innerHTML;
document.getElementById('con_div').innerHTML = '';</script>"; ?>
}
</div>
Your end curly should be inside the ?>
</form>
<?php if(isset($_POST['isyac'])) {
echo "<script language='javascript'>window.backUpHtml = document.getElementById('con_div').innerHTML;
document.getElementById('con_div').innerHTML = '';</script>";
}
?>
</div>
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();