Hide element button - php

I have a hide button code which does hide any div or element i want however the problem is i have a data table which displays more than one select option for each row in the table
if the order has 3 items it will display the 3 items with the 3 select options
however the hide button only works for the first one and not for the other 2 each select option has its own button generated
my code is below
<?php defined('BASEPATH') OR exit('No direct script access allowed'); ?>
<script>
$(document).ready(function () {
$(".edit_status_combo").change(function (event) {
var row_id = $(this).closest("tr").find(".row_id").val();
var delivery_id = $(this).closest("tr").find(".delivery_id").val();
var status = $(this).closest("tr").find(".edit_status_combo").val();
jQuery.ajax({
type: "POST",
url: "<?php echo base_url(); ?>" + "index.php/sales/view_delivery",
data: {row_id: row_id, delivery_id:delivery_id, i_status: status}
})
})
})
jQuery(document).ready(function(){
jQuery('#hideshow1').on('click', function(event) {
jQuery('#edit_status_combo').toggle('show');
});
});
</script>
<div class="modal-dialog modal-lg no-modal-header">
<div class="modal-content">
<div class="modal-body">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">
<i class="fa fa-2x">×</i>
</button>
<button type="button" class="btn btn-xs btn-default no-print pull-right" style="margin-right:15px;" onclick="window.print();">
<i class="fa fa-print"></i> <?= lang('print'); ?>
</button>
<?php if ($logo) { ?>
<div class="text-center pull-left" style="margin-bottom:20px;" >
<img src="<?= base_url() . 'assets/uploads/logos/' . $biller->logo; ?>"
alt="<?= $biller->company != '-' ? $biller->company : $biller->name; ?>">
</div>
<?php } ?>
<div class="table-responsive">
<table border="0" cellpadding="0" cellspacing="0" width="100%" style = "border-collapse: collapse;" >
<tbody style="font-size: 12px !important;">
<tr>
<td><div class="col-xs-19 text-left"><?= lang("customer"); ?>: <?= $delivery->customer; ?></div></td>
<td><div class="col-xs-19 text-right"><?= lang("sale_reference_no"); ?>: <?= $delivery->sale_reference_no; ?></div></td>
</tr>
<tr>
<td><div class="col-xs-19 text-left"><?= lang("address"); ?>: <?= $delivery->address; ?></div></td>
<td><div class="col-xs-19 text-right"><?= lang("do_reference_no"); ?>: <?= $delivery->do_reference_no; ?></div></td>
</tr>
<tr>
<td><div class="col-xs-19 text-left"></div></td>
<td><div class="col-xs-19 text-right"><?= lang("Estimated Delivery Date"); ?>: <?= $this->sma->hrld($delivery->date); ?></div></td>
</tr>
<tr>
<td><div class="col-xs-19 text-left"></div></td>
<td><div class="col-xs-19 text-right"><?= lang("status"); ?>: <?= $delivery->status; ?></div></td>
</tr>
<tr>
<td><div class="col-xs-19 text-left"></div></td>
<td><div class="col-xs-19 text-right"><?= lang("Staff Name"); ?>: <?= $user->first_name . ' ' . $user->last_name; ?></div></td>
</tr>
</tbody>
</table>
</div>
<h3><?= lang("items"); ?></h3>
<div class="table-responsive">
<table class="table table-bordered table-hover table-striped" >
<thead >
<tr>
<th style="text-align:center; vertical-align:middle;"><?= lang("no"); ?></th>
<th style="vertical-align:middle;"><?= lang("description"); ?></th>
<th style="text-align:center; vertical-align:middle;"><?= lang("quantity"); ?></th>
<th class="status_column_table"><?= lang("product_status"); ?></th>
</tr>
</thead>
<tbody>
<?php $r = 1;
foreach ($rows as $row): ?>
<tr>
<td style="text-align:center; width:40px; vertical-align:middle;"><?= $r; ?></td>
<td style="vertical-align:middle;">
<?= $row->product_code ." - " .$row->product_name .($row->variant ? ' (' . $row->variant . ')' : '');
if ($row->details) {
echo '<br><strong>' . lang("product_details") . '</strong> ' .
html_entity_decode($row->details);
}
?>
</td>
<td style="width: 150px; text-align:center; vertical-align:middle;"><?= $this->sma->formatQuantity($row->unit_quantity).' '.$row->product_unit_code; ?></td>
<td style="text-align:center; width:40px; vertical-align:middle;">
<input class = "row_id" type="hidden" name="row_id_text" value="<?= $row->product_id;?>">
<input class = "delivery_id" type="hidden" name="delivery_id_text" value="<?= $delivery->id;?>">
<div class='no-print'><input type='button' id='hideshow1' value=''></div>
<select id="edit_status_combo" name="item_status">
<option value="delivering" <?= $row->status=='delivering' ? 'selected' : '';?>>Delivering</option>
<option value="delivered" <?= $row->status=='delivered' ? 'selected' : '';?>>Delivered</option>
<option value="waiting" <?= $row->status=='waiting' ? 'selected' : '';?>>Waiting</option>
<option value="returned" <?= $row->status=='returned' ? 'selected' : '';?>>Returned</option>
<option value="wrong" <?= $row->status=='wrong' ? 'selected' : '';?>>Wrong</option>
<option value="damaged" <?= $row->status=='damaged' ? 'selected' : '';?>>Damaged</option>
<option value="missing" <?= $row->status=='missing' ? 'selected' : '';?>>Missing</option>
</select>
</td>
</tr>
<?php
$r++;
endforeach;
?>
</tbody>
</table>
</div>
<div class="table-responsive">
<table border="0" cellpadding="0" cellspacing="0" width="100%" style = "border-collapse: collapse;" >
<tbody style="font-size: 12px !important;">
<tr>
<td width="6%"><div class="form-group pull-left"><?= lang("ccf1", "cf1"); ?>
<?php echo form_checkbox('cf1', 'cf1', $customer->cf1, 'class="form-control" id="cf1"'); ?></div></td>
<td width="6%"><div class="form-group pull-left"><?= lang("ccf2", "cf2"); ?>
<?php echo form_checkbox('cf2', 'cf2', $customer->cf2, 'class="form-control" id="cf2"'); ?></div></td>
<td width="12%"<div class="form-group pull-left"> <?= lang("ccf3", "cf3"); ?>
<?php echo form_checkbox('cf3', 'cf3', $customer->cf3, 'class="form-control" id="cf3"'); ?></div></td>
<td width="12%"><div class="form-group pull-left"><?= lang("ccf4", "cf4"); ?>
<?php echo form_checkbox('cf4', 'cf4', $customer->cf4, 'class="form-control" id="cf4"'); ?></div></td>
<td width="63%"></td>
</tr>
</tbody>
</table>
</div>
<div class="clearfix"></div>
<?php if ($delivery->note) { ?>
<div class="well well-sm">
<p class="bold" style="font-size:11px;"><?= lang("note"); ?>:</p>
<div style="font-size:11px;"><?= $this->sma->decode_html($delivery->note); ?></div>
</div>
<?php } ?>
<p class="bold" style="font-size:11px;"><?= lang("Customer Satisfaction"); ?>:</p>
<input type="text" id="txtbox123">
<br>
<br>
<div class="row">
<div class="col-xs-4 pull-left">
<p style="height:30px; font-size:11px;"><?= lang("received_by"); ?> : </p>
<hr style="height:1px;border:none;color:#333;background-color:#333;">
<p style="font-size:11px;"><?= lang("Receiver/Customer Signature"); ?></p>
</div>
<div class="col-xs-4 pull-right">
<p style="height:30px; font-size:11px;"><?= lang("delivered_by"); ?>: </p>
<hr style="height:1px;border:none;color:#333;background-color:#333;">
<p style="font-size:11px;"><?= lang("stamp_sign"); ?></p>
</div>
</div>
</div>
</div>
</div>
the jquery is at the top
how can i make it so it works each time it is generated below is a example of the select elements
as you can see the first row select element was succesfully hidden the others do not work
enter image description here

You could change the #edit_status_combo and add a class to the element, lets call it .edit_status_combo then you could use a .each() so:
jQuery(document).ready(function(){
jQuery('#hideshow1').on('click', function(event) {
jQuery('.edit_status_combo').each(function(){
jQuery(this).toggle('show');
});
});
});

Related

How do I stop user from leaving quantity empty?

So this is my order page and I want to add an option which prevents the user from leaving the quantity option empty. I cannot seem to use the required option as it compels the user to fill every box instead of the one just selected.
Here is the code
<body>
<?php include('navbar.php'); ?>
<div class="container">
<h1 class="page-header text-center">ORDER</h1>
<form method="POST" action="purchase.php">
<table class="table table-striped table-bordered">
<thead>
<th class="text-center"><input type="checkbox" id="checkAll"></th>
<th class="productheading">Category</th>
<th class="productheading">Product Image
<th class="productheading">Product Name</th>
<th class="productheading">Price</th>
<th class="productheading">Quantity</th>
</thead>
<tbody>
<?php
$sql = "select * from product left join category on category.categoryid=product.categoryid order by product.categoryid asc, productname asc";
$query = $conn->query($sql);
$iterate = 0;
while ($row = $query->fetch_array()) {
?>
<tr>
<td class="text-center"><input type="checkbox" value="<?php echo $row['productid']; ?>||<?php echo $iterate; ?>" name="productid[]" style=""></td>
<td><?php echo $row['catname']; ?></td>
<td><a href="<?php if (empty($row['photo'])) {
echo "upload/noimage.jpg";
} else {
echo $row['photo'];
} ?>"><img src="<?php if (empty($row['photo'])) {
echo "upload/noimage.jpg";
} else {
echo $row['photo'];
} ?>" height="170px" width="80%"></a></td>
<td class="productname1"><?php echo $row['productname']; ?></td>
<td class="price">Rs <?php echo number_format($row['price'], 2); ?></td>
<!-->**HERE IS THE CODE THAT NEEDS TO BE FIXED**--> <td><input type="number" class="form-control" name="quantity<?php echo $iterate; ?>"></td>
</tr>
<?php
$iterate++;
}
?>
</tbody>
</table>
<div class="row">
<div class="col-md-3">
<input type="text" name="customer" class="form-control" placeholder="Customer Name" required>
</div>
<div class="col-md-3">
<input type="number" name="number" class="form-control" placeholder="Contact Number" required>
</div>
<div class="col-md-2" style="margin-left:-20px;">
<button type="submit" onclick="myFunction()" class="btn btn-primary"><span class="glyphicon glyphicon-floppy-disk"></span> Order</button>
<br />
<br />
<br />
</div>
</div>
</form>
</div>
<script type="text/javascript">
$(document).ready(function() {
$("#checkAll").click(function() {
$('input:checkbox').not(this).prop('checked', this.checked);
});
});
</script>
</body>
</html>
You can target those fields with jQuery/JavaScript and make it required by focusing on it and then prevent the form from submitting. Try this
$(document).ready(function() {
$('#order-form').submit(function(e){
let $quantities = $(this).find('.table input[type="number"]').filter(function(){
return $(this).closest('tr').find('input[type="checkbox"]').is(':checked') && $(this).val() === '';
})
if( $quantities.length > 0 ){
e.preventDefault();
$quantities.first().focus()
}
})
});
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap#3.3.7/dist/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<div class="container">
<form method="POST" action="purchase.php" id="order-form">
<table class="table table-striped table-bordered">
<thead>
<th class="text-center"><input type="checkbox" id="checkAll"></th>
<th class="productheading">Category</th>
<th class="productheading">Product Image
<th class="productheading">Product Name</th>
<th class="productheading">Price</th>
<th class="productheading">Quantity</th>
</thead>
<tbody>
<tr>
<td class="text-center"><input type="checkbox" value="1" name="productid[]" checked></td>
<td>Dishes</td>
<td><img src="https://via.placeholder.com/150/0000FF/FFFFFF?text=Bara" height="170px" width="80%"></td>
<td class="productname1">Bara</td>
<td class="price">Rs 79.00</td>
<td><input type="number" class="form-control" name="quantity[]"></td>
</tr>
<tr>
<td class="text-center"><input type="checkbox" value="1" name="productid[]"></td>
<td>Dishes</td>
<td><img src="https://via.placeholder.com/150/FF0000/FFFFFF?text=Chwela" height="170px" width="80%"></td>
<td class="productname1">Chwela</td>
<td class="price">Rs 120.00</td>
<td><input type="number" class="form-control" name="quantity[]"></td>
</tr>
</tbody>
</table>
<button type="submit" class="btn btn-primary"><span class="glyphicon glyphicon-floppy-disk"></span> Order</button>
</form>
</div>
Answer in format requested by the OP
<body>
<?php include('navbar.php'); ?>
<div class="container">
<h1 class="page-header text-center">ORDER</h1>
<form method="POST" action="purchase.php" id="order-form">
<table class="table table-striped table-bordered">
<thead>
<th class="text-center"><input type="checkbox" id="checkAll"></th>
<th class="productheading">Category</th>
<th class="productheading">Product Image
<th class="productheading">Product Name</th>
<th class="productheading">Price</th>
<th class="productheading">Quantity</th>
</thead>
<tbody>
<?php
$sql = "select * from product left join category on category.categoryid=product.categoryid order by product.categoryid asc, productname asc";
$query = $conn->query($sql);
$iterate = 0;
while ($row = $query->fetch_array()) {
?>
<tr>
<td class="text-center"><input type="checkbox" value="<?php echo $row['productid']; ?>||<?php echo $iterate; ?>" name="productid[]" style=""></td>
<td><?php echo $row['catname']; ?></td>
<td><a href="<?php if (empty($row['photo'])) {
echo "upload/noimage.jpg";
} else {
echo $row['photo'];
} ?>"><img src="<?php if (empty($row['photo'])) {
echo "upload/noimage.jpg";
} else {
echo $row['photo'];
} ?>" height="170px" width="80%"></a></td>
<td class="productname1"><?php echo $row['productname']; ?></td>
<td class="price">Rs <?php echo number_format($row['price'], 2); ?></td>
<td><input type="number" class="form-control" name="quantity<?php echo $iterate; ?>"></td>
</tr>
<?php
$iterate++;
}
?>
</tbody>
</table>
<div class="row">
<div class="col-md-3">
<input type="text" name="customer" class="form-control" placeholder="Customer Name" required>
</div>
<div class="col-md-3">
<input type="number" name="number" class="form-control" placeholder="Contact Number" required>
</div>
<div class="col-md-2" style="margin-left:-20px;">
<button type="submit" class="btn btn-primary"><span class="glyphicon glyphicon-floppy-disk"></span> Order</button>
<br />
<br />
<br />
</div>
</div>
</form>
</div>
<script type="text/javascript">
$(document).ready(function() {
$("#checkAll").click(function() {
$('input:checkbox').not(this).prop('checked', this.checked);
});
$('#order-form').submit(function(e){
let $quantities = $(this).find('.table input[type="number"]').filter(function(){
return $(this).closest('tr').find('input[type="checkbox"]').is(':checked') && $(this).val() === '';
})
if( $quantities.length > 0 ){
e.preventDefault();
alert("Quantity is required")
$quantities.first().focus()
}
})
});
</script>
</body>
In case of users who have disabled Javascript, you should also check on the server for missing quantities:
// purchase.php
if (isset($_POST['productid'])) {
for ( $i=0; $i < sizeof($_POST['productid']); $i++ ) {
if ( $_POST['productid'][$i] && ! $_POST['quantity'][$i] ) {
echo "Missing quantity for " . $_POST['productid'][$i] . "<br>";
}
}
}

when i do form the popup window displays in just a second then hide again

I have popup it works normal i need to use method post to get my value from the input balise but the problem is when i do form the popup window displays in just a second then hide again and I need to click two time becausethe first time i got just the last result
<div class="List_modify">
<table class="list">
<thead class="topBar">
<tr>
<th>Prenom</th>
<th>Nom</th>
<th>CIN</th>
<th>Emails</th>
<th>Références</th>
<th>Photos</th>
<th>Niveau</th>
<th class="button_editer" style="vertical-align:middle"><span>Editer</span></th>
</tr>
</thead>
<?php $requet = "select * from Etudiants";
$resultat = mysqli_query($connecte, $requet);
while ($r = mysqli_fetch_array($resultat)) {
?>
<tbody class="container">
<tr>
<td>
<?php echo $r['Prenom']; ?>
</td>
<td>
<?php echo $r['Nom']; ?>
</td>
<td>
<?php echo $r['CIN']; ?>
</td>
<td>
<?php echo $r['Emails']; ?>
</td>
<td>
<?php echo $r['Matricule']; ?>
</td>
<td> <img src="image/<?php echo $r['Photo']; ?> " style="width: 150px; height:150px;"></td>
<td>
<?php echo $r['Niveau']; ?> </td>
<td>
<form method="POST" action="">
<input type="hidden" name="id" value="<?php echo $r['Id_Etudiant']; ?>">
<button class=" button" onclick="show()" style="vertical-align:middle" type="submit" name="submit"><span>Editer<i class=" fas fa-user-edit"></i></span>
</button>
</form>
</td>
</tr>
</tbody>
<?php } ?>
</table>
</div>
<div class="background_page_modify" id="page_modify" onclick="hide()">
<div class="page_etudiant" onclick="event.stopPropagation()">
<div class="closebtn" id="closebtn" onclick="hide()">
<div class="circle"> +</div>
</div>
<div class="etudiant_box">
<?php
if (isset($_REQUEST['submit'])) {
$checkid = $_REQUEST['id'];
echo $checkid;
}
?>
</div>
</div>
</div>

How to make a drop down that include years and when a year is selected, it gets the people who registered in that year in a table using php

<table class="table table-striped table-bordered bootstrap-datatable datatable">
<thead>
<tr>
<th></th>
<th>Business Name</th>
<th>Commencement Date</th>
<th>Registered?</th>
<th>Business Address</th>
<th>Contact Details</th>
<th>Contact Name</th>
<th> </th>
</tr>
</thead>
<tbody>
<?
db_connect();
$result=mysql_query("select * from hbs_participants_register ORDER BY hbs_id DESC");
$num_result=mysql_num_rows($result);
?>
<tr>
<?
for ($i=0; $i<$num_result; $i++) {
$row=mysql_fetch_array($result);
?>
<td width="10"><div align="left">
<?php echo $i+1; ?>
</div>
</td>
<td><div align="left">
<? echo $row['hbs_bus_name'] ?>
</div>
</td>
<td><div align="left">
<? echo $row['hbs_com_date'] ?>
</div>
</td>
<td><div align="left">
<? echo $row['hbs_bus_reg']; ?>
<br /> <strong><?php if (!empty($row['hbs_bus_regnumber'])) {
echo "Reg No. ".$row['hbs_bus_regnumber'];
} else {} ?></strong>
</div>
</td>
<td><div align="left">
<? echo $row['hbs_bus_address']; ?>
<br />
</div>
</td>
<td><div align="left">
<? echo $row['hbs_email']; ?>
<br />
<? echo $row['hbs_phone']; ?>
<br />
<? echo $row['hbs_url']; ?>
<br />
</div>
</td>
<td><div align="left">
<? echo $row['hbs_contact_name']; ?>
</div>
</td>
<td>
<div class="btn-group">
<button class="btn btn-small dropdown-toggle"
data-toggle="dropdown">
<i class="icon-cog"></i> <strong
style="font-size: 14px; padding: 5px 0px"> Manage</strong><span
class="caret"></span>
</button>
<ul class="dropdown-menu">
<li><a
href="../../print-busreg.php?hbs_id=<?php echo $row['hbs_id'];?>"
target="_blank"><i class="icon-list"></i> Full Details</a>
</li>
<li><a
href="?w=plugins/HBS%202015/delete-busreg&hbs_id=<?php echo $row['hbs_id'];?>&action=delete"
onclick="return confirm('Are you sure you want to delete?')"><i
class="icon-trash"></i> Delete</a>
</li>
</ul>
</div>
</td>
</tr>
<? } ?>
</tbody>
</table>
I believe this should work, assuming you are storing the data together with the year it was submitted. This is not the whole code you need, just the part which lets you select a year and get it from the Dbase.
<form method="get" action="page.php" enctype="multipart/form-data">
year:
<select name="selectedYear">
<option value="2000">2000</option>
<option value="2001">2001</option>
<option value="2002">2002</option>
<option value="2003">2003</option>
<option value="2004">2004</option>
</select>
<input type="submit" name="submit">
</form>
PHP
<?php
$year = $_GET['selectedYear'];
?>
So then you just get all the columns that contain that year:
mysql_query('"select * from hbs_participants_register WHERE year LIKE" . $year . "ORDER BY hbs_id DESC"');

Show only relevant search results

I have created a page for search, and I'm having some problems.
The data is displayed on the page but I also use some fields on the form for a specific field, so when I enter the data in those fields and hit search, it shows the search field on the top of the display page with the rest of the data, but I want only the data which belongs to my search.
CODE:
<?php
include('connect.php');
?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<?php include('include/head.php')?>
</head>
<body>
<div id="header-wrapper">
<div id="header">
<div id="menu">
<ul>
<?php include('include/menu.php') ?>
Logout
</ul>
</div>
</div>
</div>
<div id="logo">
<?php include('include/logo.php'); ?>
</div>
<div id="wrapper">
<div id="page">
<div id="page-bgtop">
<div id="content">
<div class="post">
<div class="entry-image">
<?php
$q=mysql_query("SELECT count( php ) AS ph, count( dotnet ) AS dot, count( design ) AS des FROM candidate");
while($row=mysql_fetch_array($q))
{
?>
<form name="" method="post">
<table border="1" cellpadding="10" cellspacing="1" width="280" height="200">
<th colspan="5" bgcolor="orange" >Total Number of Resume by skills</th>
<tr>
<th><B>PHP</B></th>
<th><B>DOTNET</B></th>
<th><B>DESIGN</B></th>
</tr>
<td><?php echo "$row[ph]"; ?></td>
<td><?php echo "$row[dot]"; ?></td>
<td><?php echo "$row[des]"; ?></td>
</table>
</form>
<?php
}
?>
</div>
<h2 class="title">Welcome to Resume </h2>
<div class="entry">
<p>
<form name="search" method="post" action="searchview.php">
<table>
<tr>
Id: <input type="text" name="id" /></br></br>
Name:<input type="text" name="name" /><br/></br>
Expected Salary:<input type="text" name="es" /><br/></br>
Skill Rate: <input type="text" name="sr" /><br/> </br>
Salary:<input type="text" name="cs" /></br></br>
<input type="submit" name="submit" value="seach" /><input type="reset" name="reset" value="reset" />
</tr>
</table>
</form>
</p>
</div>
</div>
<div class="post" >
<?php
$query=mysql_query("select * from candidate");
while($row=mysql_fetch_array($query))
{
$sno=$row['id'];
$image=$row['image'];
$name=$row['fname'];
$es=$row['es'];
$sr=$row['sr'];
$cs=$row['cs'];
?>
<form name="view" method="post" action="searchview.php" >
<table border="1" cellpadding="30" class="centered" width="20" >
<tr>
<th width="150">S.NO</th>
<th width="150">IMAGE</th>
<th width="150">NAME</th>
<th width="150">EXPECTED SALARY</th>
<th width="150">SKILL RATE</th>
<th width="150">SALARY</th>
<th width="150">ACTION</th>
</tr>
<td><?php echo "$row[id]"; ?></td>
<td><div class="rightdiv1a"><img src="<?php echo 'img/'.$row['image']; ?>" style="height:120px; width:145px; "></div></td>
<td><?php echo "$row[fname]"; ?></td>
<td><?php echo "$row[es]"; ?></td>
<td><?php echo "$row[sr]"; ?></td>
<td><?php echo "$row[cs]"; ?></td>
<td><img alt='view' title='view' src='images/view.png' width='15px' height='15px' hspace='20' /></td>
<td><img alt='Edit' title='Edit' src='images/edit.png' width='15px' height='15px' hspace='20' /></td>
<td><a onclick="return confirm('Would you like to delete?');" href="delete.php?id=<?php echo "$row[id]"; ?>"><img alt='delete' title='delete' src='images/delete.png' width='15px' height='15px' hspace='20' /></a></td>
</table>
</form>
<?php
}?>
</div>
</div>
</div>
</div>
</div>
<div id="footer-bgcontent">
<div id="footer">
<?php// include('include/footer.php');?>
</div>
</div>
</body>
</html>
<?php// } ?>
This code displays the data now but I want to filter the data and only show the results which belongs to my search, and have the rest disappear.
Here are some screenshots of my form:
pls help,
thanks in advance..
If I understand the question correctly, you want to display the search results, but no longer show the search form. If this is the case, then move your second "post" div to the top and wrap it in an if:
if (!empty($_POST)) {
// Process POST results here:
...
die(); // end processing so the form doesn't display again
}

ajax post in search

I make search form and I'm using it as ajax searchform.
I have problems in html(data), when I put the html(data) it will display the loading image and the table too it will double here's my code:
$(document).ready(function(){
$("#loading").hide();
<?php $type_temp = (!empty($type)) ? 'company/' .$type:'company';?>
$("#search_id").click(function(){
$("#loading").show();
$.post("<?php echo url_for('/AdmSys_dev.php/' .$type_temp); ?>", $("#send_search").serialize(), function(data){
$(".result").html(data);
});
});
});
How will I put the result into the page?
heres my html code below
<div id="sf_admin_content">
<h2>Company</h2><br />
<div style="margin-bottom:20px;">
<form id="send_search" action="" method="get">
<input type="text" name="search" placeholder="Search: " value="<?php echo $search; ?>" />
<input id="search_id" type="button" value="Search" />
</form>
</div>
Add
<div id="loading" style="margin-left:186px; margin-top:30px;">
<img alt="" src="/images/preloader_transparent.gif" />
</div>
<table class="location" cellspacing="0" style="width:500px;">
<thead>
<tr>
<th>Id</th>
<th>Name</th>
<th>Description</th>
<th>Photo</th>
<th>Option</th>
</tr>
</thead>
<tbody class="result">
<?php foreach($company as $x => $companies): ?>
<tr id="company<?php echo $companies->getId(); ?>" class="<?php echo ($x&1) ? 'even':'odd'; ?>">
<td align="right"><?php echo $companies->getId(); ?></td>
<td><?php echo $companies->getName(); ?></td>
<td><?php echo $companies->getDescription(); ?></td>
<td><img alt="" src="/uploads/company/<?php echo $companies->getImageFull(); ?>" /></td>
<td align="right">
<a href="<?php echo url_for('company/edit?id=' .$companies->getId() )?>">
<img alt="edit" src="/images/pencil.png" />
</a>
<a href="#delete" title="delete" onclick="return goDelete(<?php echo $companies->getId(); ?>)">
<img alt="delete" src="/images/delete.png" />
</a>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<?php
$type_temp = (!empty($type))?'company/'.$type:'company';
$data = array(
'maxPerPage' => $company->getmaxPerPage(),
'lastPage' => $company->getlastPage(),
'nbResults' => $company->getnbResults(),
'curPage' => $curPage,
'linkPage' => '/AdmSys.php/company'.$type_temp. '?search'.$search
);
include_partial('event/pager',$data); ?>
</div>
as youve notice i put the class results in the <tbody class="result></tbody>

Categories