Hi i got 2 dropdown list (client and product) and 1 content data. The product dropdown list is depended from the choice in client dropdown list (i've already done that). The problem is i want the content data is autoloaded depend on the choice in product dropdown list.
Here is my code:
<script>
function filterClient(str) {
if (window.XMLHttpRequest) {
// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp = new XMLHttpRequest();
} else {
// code for IE6, IE5
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
document.getElementById("ProductOpt").innerHTML = xmlhttp.responseText;
}
}
xmlhttp.open("GET","filter_client.php?f=client&q="+str,true);
xmlhttp.send();
}
function filterProduct(str) {
if (window.XMLHttpRequest) {
// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp = new XMLHttpRequest();
} else {
// code for IE6, IE5
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
document.getElementById("content").innerHTML = xmlhttp.responseText;
}
}
xmlhttp.open("GET","filter_product.php?f=product&k="+str,true);
xmlhttp.send();
}
</script>
<table border='0' style='float: right'>
<tr>
<td>
<form>
<select name='ClientFilter' onchange="filterClient(this.value);">
<option value='0' style="text-align: center">--Filter by Client--</option>
<?php
$clientDL = mysql_query("SELECT * FROM `Client`");
while($client=mysql_fetch_array($clientDL))
echo "<option value='".$client['ClientID']."'>".$client['ClientName']."</option>";
?>
</select>
</form>
</td>
<td>
<form>
<select name='ProductFilter' id="ProductOpt" onchange="filterProduct(this.value);">
<option value='' style="text-align: center">--Filter by Product--</option>
</select>
</form>
</td>
</tr>
</table>
<div id="content"></div>
filter_client.php:
<?php
if (file_exists("../../../../wp-load.php")) {
require_once("../../../../wp-load.php");
}
$k = $_GET['k'];
global $dbhandle;//Database connection
if($q!=0) {
if (isset($_GET['f']) && $_GET['f'] == 'client') {
$productDL = mysql_query("SELECT * FROM `Product` where ProductID = " . $k);
while ($product = mysql_fetch_array($productDL))
echo "<option value='" . $product['ProductID'] . "'>" . $product['ProductName'] . "</option>";
}
}
?>
filter_product.php:
<?php
if (file_exists("../../../../wp-load.php")) {
require_once("../../../../wp-load.php");
}
$q = $_GET['k'];
global $dbhandle;//Database connection
if(isset($_GET['f'])&&$_GET['f']=='product'){
$result = mysql_query("SELECT * from `Invoice` WHERE ProductID= ".$k);
}
$list_Client = array();
while($row=mysql_fetch_object($result)){
$list_Client[] = $row;
}
// Load data from db and show it in div id = content
?>
Related
I am working on a project at the moment. In iI am using ajax to update and calculate scores, which works fine. However, I have a color scheme that changes according to the score. The color does change, but only after the page is refreshed. Is there anyway I can get the color to change with refreshing the page?
Here is the code that I am using to assign colors:
<?php $row_class = "";
while($row = mysql_fetch_assoc($dbResult1))
{
if($row['total_mai'] <= 2)
$row_class = "success";
else if($row['total_mai'] >= 5)
$row_class = "danger";
else if($row['total_mai'] >= 3 and $row['total_mai'] < 5)
$row_class = "warning";
// echo $row_class;
?>
In another page, here is an example of one question, it has three answers and depending on the answer a color is assigned based on the score
<tr>
<td class="form-group col-md-6">Is the duration of therapy acceptable?</td>
<td class="form-group col-md-6">
<p class="radio-inline">
<input type="radio" name="therapydur" id="j1" value="0" <?php echo $j1; ?> required onchange="ajaxFunction('therapydur','<?php echo $count; ?>','0','<?php echo $row['p_id']; ?>')">
A
</input></p>
<p class="radio-inline">
<input type="radio" name="therapydur" id="j2" value="0" <?php echo $j2; ?> required onchange="ajaxFunction('therapydur','<?php echo $count; ?>','0','<?php echo $row['p_id']; ?>')">
B
</input></p>
<p class="radio-inline">
<input type="radio" name="therapydur" id="j3" value="1" <?php echo $j3; ?> required onchange="ajaxFunction('therapydur','<?php echo $count; ?>','1','<?php echo $row['p_id']; ?>')">
C
</input></p>
</td>
</tr>
Here is the ajax from the same page:
<script language="javascript" type="text/javascript">
function ajaxFunction(title,id,val,p_id)
{
//alert("test");
//alert(id);
//alert(val);
//alert(title);
//alert(p_id);
var xmlhttp;
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
//alert(xmlhttp.responseText);
var resp = xmlhttp.responseText;
var split_v = resp.split("__");
//alert(split_v.length);
//alert(split_v[1]);
document.getElementById("ajaxDiv_"+id).innerHTML=split_v[0];
document.getElementById("ajaxTotal").innerHTML=split_v[1];
}
}
xmlhttp.open("GET","ajax_mai.php?pdr_id="+id+"&value="+val+"&title="+title+"&p_id="+p_id,true);
xmlhttp.send();
return true;
}
</script>
what i'm trying to doing is when user click on php select option.then
it's value should pass to another page as variable.
there is a code i'm
trying.
<table>
<tr><td>
<?php
mysql_connect("localhost","root","") or die(mysql_error());
mysql_select_db("member")or die(mysql_error());
$result = mysql_query("SELECT id,ugroup FROM ugroups");
?>
<select name='group' id='group' >
<?php
while ($line = mysql_fetch_array($result)) {
echo '<option value=' . $line['ugroup'] . '>' . $line['ugroup'] . '</option>';
}?>
</select>
click
</td></tr>
</table>
this is add_group.php code
<?php
session_start();
ob_start();
include('../limoconfig.php');
if(!isset($_SESSION['adminuserid']) )
{
header('Location:../index.php');
}
else
{
if($_GET)
{
$ugroup = $_GET['ugroup'];
/*$id = $_GET['id'];*/
$acc_status = "update users set ugroup='".$ugroup."' where id=1931";
echo $acc_status;
$rate = db::getInstance()->exec($acc_status);
header('Location:../home.php');
}
}
?>
it's not working.
First of all you need to put your table within
and then you can call ajax on click of your anchor ().
jQuery(document).ready(function($) {
var data='';
$("#group option:selected").each(function() {
if ($(this).attr('value') !== '') {
data=$(this).attr('value');
}
});
$("a").click(function() {
$.ajax({
type: "POST",
url: "file.php",
data: data,
beforeSend: function() {
$('body').css("opacity", "0.3");
},
success: function(response) {
alert(response);
},
complete: function() {
$('body').css("opacity", "1");
}
});
});
});
Wrap it in a form tag and create a submit button instead of the link and it can send it in either POST or GET.
The element is a form control and can be used in a form to collect user input.
http://www.w3schools.com/tags/tag_select.asp
you can either do it with ajax or just using html forms.
eg of ajax : Just a simple eg, you can modify according to your need
<html>
<head>
function myAjax(str)
{
if (str=="")
{
document.getElementById("results").innerHTML="";
return;
}
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("results").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","add_group.php?ugroup="+str,true); // your next page
xmlhttp.send();
}
function myFunction() {
var x = document.getElementById("group").value;
myAjax(x);
}
</script>
</head>
<body>
<table>
<tr><td>
<?php
mysql_connect("localhost","root","") or die(mysql_error());
mysql_select_db("member")or die(mysql_error());
$result = mysql_query("SELECT id,ugroup FROM ugroups");
?>
<select name='group' id='group' >
<?php
while ($line = mysql_fetch_array($result)) {
echo '<option value=' . $line['ugroup'] . '>' . $line['ugroup'] . '</option>';
}?>
</select>
click
</td></tr>
</table>
<div id="results"> <!-- the echo of add_group.php gets displayed here --> </div>
</body>
</html>
The below code tries to change the Select option tag by making a Ajax call that connects to PHP on the server and retrieves data. However the below code works fine if i were to set the response text to a span tag but it does not work for Select option tag ?
<?php
$q = intval($_GET['q']);
$con=mysqli_connect("localhost","rot","ro","abc","3306");
/
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$result = mysqli_query($con,"SELECT DISTINCT(UniqueBusId) FROM cfv_busstopnames WHERE busnumber = ".$q." ");
if (!$result) {
printf("Error: %s\n", mysqli_error($con));
exit();
}
while($row = mysqli_fetch_array($result))
{
echo "<option>" . $row['UniqueBusId'] . "</option>" ;
}
mysqli_close($con);
?>
.
<script>
function showUser(str)
{
if (str=="")
{
document.getElementById("txtHint").innerHTML="";
return;
}
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("select-choice-direction").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","getdirection.php?q="+str.value,true);
xmlhttp.send();
}
</script>
<Body>
<label for="select-choice-direction">Direction</label>
<select name="select-choice-direction" id="select-choice-direction" data-native-menu="false" ">
<option> Direction heading towards?</option>
<option value="X">X</option>
<option value="Y">Y</option>
<!-- etc. -->
</select>
</Body>
Instead of
xmlhttp.onreadystatechange=function(){
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("select-choice-direction").innerHTML=xmlhttp.responseText;
}
}
try
xmlhttp.onreadystatechange=function(){
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
$('#select-choice-direction').html(xmlhttp.responseText).selectmenu( "refresh");
}
}
This tells jQuery Mobile to refresh the selectmenu widget (http://api.jquerymobile.com/selectmenu/#method-refresh)
DEMO
I want to have multiple drop down lists that perform a search in the database and echo the information in a table on the webpage.
From tutorials I have managed this, but only for one select choice. I am struggling to make the second drop down list refine the search conditions.
Drop down list 1 should be the option that searches the database for the selected value.
Drop down list 2 should add an AND condition to the sql and uses the second value to refine the search.
The code below does not pull any info from the database on change. If I remove the AND statement it will pull information from the database.
HTML:
<!DOCTYPE html>
<html>
<head>
<title> Vault of Faults-Fault Search </title>
<link rel="stylesheet" type="text/css" href="mystyle1.css">
<script src="dropdownfix1.js"></script>
</head>
<body>
<div id=container>
<div id=header>
<div id=headdiv>
<form id=login name="login" action="login.php" method="post">
<fieldset class="field_set">
<legend>Administrator Login:</legend> <!-- legeng tage creates a header title for the fieldset box, filedset pulls all data in the tag to gether with a box around it. -->
UserName: <input type="text" name="username"> <br>
Password:<br> <input type="password" name="password"> <br>
<input type="submit" value="Login"> <input type="Button" onClick="parent.location='addafix.php'" Value="Add a Fix">
</fieldset>
</form>
</div>
</div>
<div id=content>
<div id=maincontent>
<div id=select>
<form>
<fieldset class="field_set2">
<legend>Quicklink Vault of Faults Search</legend>
Product:
<select name="Product" onchange="showUser(this.value)">
<option value="0">Select Product</option>
<option value="1">Merlin</option>
<option value="2">Encoder</option>
<option value="3">Mac Live</option>
<option value="4">Windows Live</option>
<option value="5">Windows S&F</option>
<option value="6">Mac S&F</option>
</select>
<select name="Product_Issue" onchange="showIssue(this.value)">
<option value="0">Select Issue</option>
<option value="1">Preview</option>
<option value="2">Live Reciever</option>
<option value="3">Mac Live</option>
<option value="4">Windows Live</option>
<option value="5">Windows S&F</option>
<option value="6">Mac S&F</option>
</select>
<input type="submit" value="Search">
</fieldset>
</form>
</div>
<div id=list>
<div id="txtHint"><b>Person info will be listed here.</b></div>
</div>
</div>
</div>
</div>
</body>
</html>
JavaScript:
function showUser(str)
{
if (str=="")
{
document.getElementById("txtHint").innerHTML="";
return;
}
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","getuser.php?q="+str,true);
xmlhttp.send();
}
function showIssue(str)
{
if (str=="")
{
document.getElementById("txtHint").innerHTML="";
return;
}
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","getuser.php?p="+str,true);
xmlhttp.send();
}
PHP:
<?php
$q=$_GET["q"];
$p=$_GET["p"];
require 'connection.php';
mysqli_select_db($con,"Faults" );
//where statement in the sql syntax will select where in db to get infor, use AND to add another condition
$sql="SELECT Products.Product_Name, Versions.Version, Platform.Platform_Name, Issues.Issue, Issues.Sub_Issue, Issues.Fix
FROM Solutions INNER JOIN Products ON Solutions.Product = Products.Product_id
INNER JOIN Versions ON Solutions.Product_Version = Versions.Version_id
INNER JOIN Platform ON Solutions.Product_Platform = Platform.Platform_id
INNER JOIN Issues ON Solutions.Product_Issue = Issues.Issue_id
WHERE Product = '".$q."' AND Product_Issue = '".$p."'";
$result = mysqli_query($con,$sql);
//below is the echo statment to create the results in a table format, list collumn titles
echo "<table id=tables border='1'>
<tr>
<th>Products</th>
<th>Version</th>
<th>Platform</th>
<th>Issue</th>
<th>Sub Issue</th>
<th>Fix</th>
</tr>";
//below is script to list reults in a table format, $row [row name on table]
while($row = mysqli_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['Product_Name'] . "</td>";
echo "<td>" . $row['Version'] . "</td>";
echo "<td>" . $row['Platform_Name'] . "</td>";
echo "<td>" . $row['Issue'] . "</td>";
echo "<td>" . $row['Sub_Issue'] . "</td>";
echo "<td>Fix</td>";
echo "</tr>";
}
echo "</table>";
// below closes the coonection to mysql
?>
I think you need to concat the values of the dropdownlist. Something like:
<script type="text/javascript">
function server(aform)
{
var xmlhttp;
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","getuser.php?q="+ product.value +"&" +"p="+product_i.value ,true);
xmlhttp.send();
}
</script>
I have a combobox and i want to fill the State and Zip_code Field..its working but it fills each field State "NY11715" and Zip_code "NY11715"...i'm looking to fill State "NY" and Zip_code 11715...please help me resolve this
<select name="LookupCity" id="LookupCity" onchange="showZip(this.value)">
<option value="" <?php if (!(strcmp("", $_GET['City']))) {echo "selected=\"selected\"";} ?>>Select from menu</option>
<?php do { ?>
<option value="<?php echo $row_fmCity['City']?>"<?php if (!(strcmp($row_fmCity['City'], $_GET['City']))) {echo "selected=\"selected\"";} ?>><?php echo $row_fmCity['City']?></option>
<?php
} while ($row_fmCity = mysql_fetch_assoc($fmCity));
$rows = mysql_num_rows($fmCity);
if($rows > 0) {
mysql_data_seek($fmCity, 0);
$row_fmCity = mysql_fetch_assoc($fmCity); } ?> </select>
select</td>
</tr><tr valign="baseline">
<td nowrap="nowrap" align="right">State:</td>
<td><input type="text" name="State" id="State" placeholder="NY" value="<?php echo $_GET['State']; ?>" size="5"/>
<input type="text" name="Zip_Code" id="Zip_Code"placeholder="zip code" value="<?php echo $_GET['Zip']; ?>" size="10" /></td>
Ajax code
function showZip(str)
{
if (str=="")
{
document.getElementById("State").innerHTML="";
document.getElementById("Zip_Code").innerHTML="";
return;
}
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("State").value=xmlhttp.responseText;
document.getElementById("Zip_Code").value=xmlhttp.responseText;
}
}
xmlhttp.open("GET","Getzip.php?q="+str,true);
xmlhttp.send();
}
PHP Code
<?php
$q=$_GET["q"];
$con = mysql_connect('localhost', 'root', 'root');
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("Leadbook", $con);
$sql="SELECT * FROM Zip WHERE City = '".$q."'";
$result = mysql_query($sql);
while($row = mysql_fetch_array($result))
{
$State = $row['State'];
$Zip_Code = $row['Zip Code'];
}
echo $State;
echo $Zip_Code;
mysql_close($con);
?>
1. change your php code, so that both city and zip code are comma seperated.
change this code:
echo $State;
echo $Zip_Code;
to this:
echo $State;
echo ",";
echo $Zip_Code;
2. than update your javascript, so that the return text is splitted into 2 parts and gets to its respected fields.
change this code:
document.getElementById("State").value=xmlhttp.responseText;
document.getElementById("Zip_Code").value=xmlhttp.responseText;
to this:
var string = xmlhttp.responseText;
var array = string.split(',');
document.getElementById("State").value=array[0];
document.getElementById("Zip_Code").value=array[1];
this should do what you requested.