Make menu selection before while loop is done - javascript

I have a for I=1 to 5 loop with sleep for 5 seconds.
How can I make a menu selection and continue to another page before the while loop is done.
Now when I chose the menu item the selection will take place when the while loop is done. Its about 30 seconds.
I have tried to put the while loop in an Iframe, and load it from another page, but it still first load next page when while loop is done.
From index page
<link rel="icon" href= (./image/favicon.ico)/>
<link rel="stylesheet" href="./db/abcss.css" type="text/css"/>
<script type="text/javascript" src="./db/CSSnav.js"></script>
</HEAD>
<body>
<div id="wrapper">
<?php
include("top.php");
include("IndexMenu.php");
?>
<div id="content75">
<div id="h4"> <br/><b><center>Velkommen til t</center></b>
</div>
<div id="h3"><br/><center> text here. </center><br/><br/>
<iframe src="./eventrul.php" name = "content_iframe"></iframe>
<?php
include("Bund.php")
?>
</body>
</html>
From while loop page
if ($info = mysql_fetch_array($data)){
echo "<div id=\"event\">";
while ($info = mysql_fetch_array($data) and $i < 5){
echo "<script>";
echo "document.getElementById('event').innerHTML = \"\"";
echo "</script>";
echo "<div id=\"event_indhold\">";
if ($info['type']==='Andet'){
$info['type'] = $info['typeandet'];
}
if ($info['emne']==='Andet'){
$info['emne'] = $info['emneandet'];
}
echo "<table><tr><td width = 30% > "." <B>Event nummer: </B>"."</td>"
. "<td colspan = 10>".$info['arrnr'].", Overskrift: ". $info['type']."</td></tr><br/>";
if ($info['arrangoer']!= ""){
echo "<tr><td colspan =10>"." ".$info['arrangoer']."</td> </tr>";
}
ob_flush();
flush();
sleep(4);
$i++;
echo "</div>";
}
echo "<script>";
echo "document.getElementById('event').innerHTML = \"\"";
echo "</script>";
echo "<div id=\"event_indhold\">";
echo '<font size="5px">Klikke her for at se eventlisten ';
echo "</div>";
echo "</div>";
}

You could put a break; when you know you want to exit the loop. It will simply break it.

Related

Add Check Box to each product and use the selected Check boxes values on another page

The product list will be populated from MySql Database using PHP code and is having a check box for each product.
On that page, whenever a check box is clicked, I need that product to be highlighted and store its value to some other array type variable to pass that value to another page.
Code for product list creation:
<?php
$cnt=0;
$rslt = mysqli_query($conn,"SELECT Icode,Name,Size,Style FROM productinfo");
if(!$rslt){
die(mysqli_error($conn));
}else{
echo "<table width='100%'>";
while($row = mysqli_fetch_assoc($rslt)){
if($cnt==0){
echo "<tr>";
}
echo "<td width='30%'>
<div class='card'>
<img src='upload/"."download.jpg"."' alt='Avatar' style='width:100px' >
<div class='container'>
<h4><b>".$row['Name']." <input type='checkbox' name=".$row['Icode']." value=".$row['Icode']." onclick=' echo return OptionsSelected(this)'/> </b></h4>
<p>".$row['Size']."</p>
<p>".$row['Icode']."</p>
</div>";
?>
<!-- <button role="button" data-toggle="modal" data-id="<?php print $row['Icode']?>" onclick="document.getElementById('id01').style.display='block'" style="width:auto;">Inquiry</button>
</div>
<?php
echo "</td>";
if($cnt==2){
$cnt=0;
echo "</tr>";
}
else
$cnt = $cnt + 1;
}
}
echo "</table>";
?>

Place a list inside an session and display each session

Im trying to create a shopping cart style website. I'm able to display the products through setting the products as a class and passing that through to my shopping cart page. However, I need to save the list of products into a session so I can add and or clear each item added to the cart.
Products.php
<?php
require_once 'class_product.php';
$product = new product();
$product_id =(int)$_GET['product_id']; //get id from home page
$username = "";
$password = "";
$hostname = "";//blanked this out for public use
//connection to the database
$dbhandle = mysql_connect($hostname, $username, $password)
or die("Unable to connect to MySQL");
//select a database to work with
$selected = mysql_select_db("poti",$dbhandle)
or die("Could not select examples");
//execute the SQL query and return records
$result = mysql_query("SELECT * FROM products where product_id=$product_id");
echo '<form name="form1" method="post" action="cart.php" target="bottom_right">';
echo '<table class="Grocery-table">';
while($row = mysql_fetch_array($result))
{
$product->setProductId($row['product_id']);
$product->setProductName($row['product_name']);
$product->setStock($row['in_stock']);
$product->setUnitPrice($row['unit_price']);
$product->setUnitQuantity($row['unit_quantity']);
}
$_SESSION['product'] = serialize($product);
echo "<tr><td><b>Product ID</b></td>";
echo "<td>";
echo $product->getProductId();
echo "</td></tr>";
echo "<tr><td><b>Product Name</b></td>";
echo "<td>";
echo $product->getProductName();
echo "</td></tr>";
echo "<tr><td><b>Unit Price</b></td>";
echo "<td>";
echo $product->getUnitPrice();
echo "</td></tr>";
echo "<tr><td><b>Unit Quantity</b></td>";
echo "<td>";
echo $product->getUnitQuantity();
echo "</td></tr>";
echo "<tr><td><b>In Stock</b></td>";
echo "<td>";
echo $product->getStock();
echo "</td></tr>";
echo '<tr><td><b>Add</b></td><td><Input type="number" min="0" id="add_value" name="cart"></input>
<Input type="hidden" id="stock_value" name="stock_value" value ='.trim($product->getStock()).'></input></td></tr>';
echo '<tr><td></td><td><input type="submit" value="Submit" onclick="return numCheck()"></td></tr>';
echo "</table>";
echo "</form>";
?>
cart.php
<?php
session_start();
?>
<html>
<style type="text/css">
</style>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>My Grocery Store</title>
</head>
<body>
<h2>Cart</h2>
<?php
require_once 'class_product.php';
$product = unserialize($_SESSION['product']);
//this allows me to see the information when i click submit
echo $product->getProductName();
echo $product->getProductId();
echo $product->getStock();
echo $product->getUnitPrice();
echo $_POST['cart'];
?>
</body>
</html>
How do i place the following $product->getProductName() etc into a Session that enables me to display all the products i've added to my cart.
Try this,
session_start();
$_SESSION['ProductName'] = $product->getProductName();
$_SESSION['ProductId'] = $product->getProductId();
$_SESSION['Stock'] = $product->getStock();
$_SESSION['UnitPrice'] = $product->getUnitPrice();
For multiple products, you may have to use an array of session.
<?php
session_start();
if(!isSet($_SESSION['cart_items']))
{
$_SESSION['cart_items'] = array();
}
$items =$product->getProductName()."|".$product->getProductId()."|".$product-
>getStock()."|".$product->getUnitPrice();
array_push($_SESSION['cart_items'],$items);
echo $_SESSION['cart_items'][0]; //First Product
echo "<br>";
echo $_SESSION['cart_items'][1]; //Second Product
?>

Real time filtering of a table

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Little Things</title>
<?php echo link_tag('resources/css/style.css'); ?>
<script src="http://code.jquery.com/jquery-latest.min.js" type="text/javascript"></script>
<script type="text/javascript" src="<?php echo base_url('resources/js/script.js');?>" ></script>
<script type="text/javascript">var $rows = $('#table tr');
$('#search').keyup(function() {
var val = $.trim($(this).val()).replace(/ +/g, ' ').toLowerCase();
$rows.show().filter(function() {
var text = $(this).text().replace(/\s+/g, ' ').toLowerCase();
return !~text.indexOf(val);
}).hide();
});
</script>
</head>
<body>
<div id="container">
<div id="top">
<img id="logo" src="<?php echo base_url('resources/images/logo.jpg'); ?>" alt="litLogo"/>
</div>
<div id="main">
<div id='cssmenu'>
<ul>
<li class='active'><span>Home</span></li>
<li class="element"><a href='#'><span>Shopping Cart</span></a></li>
<li class="element"><a href='#'><span>Wish List</span></a></li>
<li class="element"><a href='#'><span>Contact</span></a></li>
<li id="name">
<?php
if($this->session->userdata('email'))
{
echo "<a href='#'><span>Welcome ".$user."!</span></a>";
}
else
{
echo "<a href='#'><span>Welcome Guest!</span></a>";
}
?>
<?php
if($this->session->userdata('email'))
{
echo '<li class="element"><span>Logout</span></li>';
}
else
{
echo '<li class="element"><span>Login</span></li>';
}
?>
</li>
<li class="element"><span>Sign Up</span></li>
</ul>
</div>
<div class="tables" id="tables">
<input type="text" class="search" placeholder="Type to search">
<?php
$imgDir="../../resources/images/thumbs/";
echo "<table id='table'>";
echo "<tbody class='list'>";
echo "<tr bgcolor='#E60000'>";
echo "<th>Name</th><th>Product Line</th><th>Product Scale</th><th>Product Description</th><th>Price</th><th>Image</th>";
echo "</tr>";
$i=0;
foreach($Products as $key => $value)
{
$i++;
if($i%2==0)
{
echo "<tr bgcolor='#EE4D4D' width='100%'>";
//echo '<td>'.$value["ID"].'</td>';
echo "<td class='pName'>".$value["productName"]."</td>";
echo "<td class='pLine'>".$value["productLine"]."</td>";
echo "<td class='pScale'>".$value["productScale"]."</td>";
echo "<td class='pDes'>".$value["productDescription"]."</td>";
echo "<td class='buyPrice'>".$value["buyPrice"]."</td>";
//echo '<td>'.$value["QtySold"].'</td>';
echo "<td class='image'><img src='".$imgDir.$value['image']."' height='100' width='100'/></td>";
//echo '<td>'.$value["ABV"].'</td>';
echo "</tr>";
}
else
{
echo "<tr bgcolor='#F28080' width='100%'>";
//echo '<td>'.$value["ID"].'</td>';
echo "<td class='pName'>".$value["productName"]."</td>";
echo "<td class='pLine'>".$value["productLine"]."</td>";
echo "<td class='pScale'>".$value["productScale"]."</td>";
echo "<td class='pDes'>".$value["productDescription"]."</td>";
echo "<td class='buyPrice'>".$value["buyPrice"]."</td>";
//echo '<td>'.$value["QtySold"].'</td>';
echo "<td class='image'><img src='".$imgDir.$value['image']."' height='100' width='100'/></td>";
//echo '<td>'.$value["ABV"].'</td>';
echo "</tr>";
}
}
echo "</tbody>";
echo "</table>";
?>
</div>
<script type="text/javascript">
var options = {
valueNames: [ 'pName', 'pLine', 'pScale', 'pDes', 'buyPrice','image' ]
};
var userList = new List('tables', options);</script>
</div>
</div>
</body>
</html>
So this is my code. I am trying to filter the table as I am typing into the text box. Any help appreciated.
I've tried following the tutorials but they do not seem to work at all... any ideas?
I find it difficult to understand and apply to my own website, the code I have for filtering is taken from the internet is well.
As I see you're using jQuery so why not use contains selector? You could use it after keyUp event on select tag:
$("#search").keyup(function(){
var search = this.value;
$('#table tr, #table th').show();
$('#table td:contains('+search+')').each(function(){
$(this).parent().hide();
});
});
This code will hide any cell parent (tr, th...) which have a child td containing input value . You can use this code and make it fits better your needs.
Fiddle example: http://jsfiddle.net/uby9quLo/2/
Hope it helps!

my SetTimeout is not auto submitting my button

I have a code like
<SCRIPT LANGUAGE="JavaScript">
setTimeout('document.test.submit()',1000);
</SCRIPT>
I follow the tutorials on how to do a settimeout function but it is not working with my php code.. my Whole code looks like this..
<head>
<link rel="stylesheet" type="text/css" href="css.css" />
<SCRIPT LANGUAGE="JavaScript">
setTimeout('document.test.submit()',1000);
</SCRIPT>
</head>
and my php looks like this..
echo "<form name=\"asd\" id=\"form1\" action=\"PostTest1.php\" method=\"post\" >";
echo "<tr><td>";
echo $row['Description'] . "<br>";
echo "<input type=\"radio\" name=\"Answer\" value=\"A\"> A.)" . $row['Ans1'];
echo "<br>";
echo "<input type=\"radio\" name=\"Answer\" value=\"B\"> B.)" . $row['Ans2'];
echo "<br>";
echo "<input type=\"radio\" name=\"Answer\" value=\"C\"> C.)" . $row['Ans3'];
echo "<br>";
echo "<input type=\"radio\" name=\"Answer\" value=\"D\"> D.)" . $row['Ans4'];
echo "<br>";
echo "<input type=\"submit\" value=\"submit\" name=\"submit\">";
echo "</td></tr>";
echo "</form>";
My button is not auto clicking.. Thank you for the advance help.. :)
(Sorry for my grammar)
Try this:
setTimeout(document.getElementById("form1").submit(),1000); alternatively, you could also do this: setTimeout(document.asd.submit(),1000); since you've named your form.
You need to find the correct element to submit, document.test is not valid in your supplied scenario.
EDIT: You need to remove the name attribute from your submit button as when you call .submit() it is finding that element, rather than submitting the form like you'd expect.
Fiddle: http://jsfiddle.net/KyleMuir/yKG3U/
setTimeout needs a function to call and the timeout.
you can do:
setTimeout(my_func(), 1000);
function my_func(){
document.getElementById("id_form").submit();
}
That way should work.

Colorbox working for the first time .. but not the second time .. I get a.removeEventListener is not a function

Ok , so i am using colorbox to pop up windows of dynamic data generated by PHP .. Below is my php code ... when I click on the link , the windows pop up with the data .... but if I click on the same link again , the window doesn't get the information and I get this in the console a.removeEventListener is not a function , for the second time on clicking on the link for the colorbox to show .. 1st time works .. what could be going wrong ?
jQuery(document).ready(function() {
var id_form;
var url;
$("a.madcomment").click(function(e) {
e.preventDefault();
id_form = $(this).attr('id');
url ="#madcomment_menu"+id_form;
$("a.madcomment").colorbox({inline:true, width:"350px", href:url});
});
});
<?php
$select = "SELECT * FROM COMMENTS INNER JOIN Twitter_Data ON Twitter_Data.screen_name=Comments.Twitter WHERE Category ='Comments'";
$result = mysql_query($select);
$result_count = mysql_num_rows($result);
echo " <table border =\"0\">";
echo "<tr>";
$user_array = array();
$counter = 0;
if($result_count > 0) {
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
echo "<div id ='scoring_scale' class='madscore".$row['ID']."' style='display:none;'>";
echo "<div id='madcomment_menu".$row['ID']."' style='padding:10px; background:#fff;'>";
echo "<a id='".$row['ID']."' class='green_circle' href='#'> +3 </a>";
echo "<a id='".$row['ID']."' class='orange_circle' href='#'> +1 </a>";
echo "<a id='".$row['ID']."' class='red_circle' href='#'> -1 </a>";
echo "<a id='".$row['ID']."' class='brown_circle' href='#'> -3 </a><br />";
echo"<form>";
echo "<textarea id='text".$row['ID']."'rows='5' cols='33'>";
echo "-";
echo "</textarea>";
echo"<button id='button".$row['ID']."'class='button_madscore'> MadComment </button>";
echo "</form>";
echo "</div>";
echo "</div>";
}
}
// Here is the link that will generate the COLORBOX pop-up
echo "<a id='".$row['ID']."'class=' madcomment' href='madcomment_menu".$row['ID']."'><img src='images/madcomment.png' /> </a>";
?>
You are binding your colorbox each time on anchor click so in order to prevent this replace you colorbox code with below :
$.fn.colorbox({inline:true, width:"350px", href:url});
This will fix your issue.

Categories