I've one array, which is output of some function and size of array is dynamic. So, I want to put all array element as drop-down with checkbox. Can anyone is here to help?
<select name="per1" id="per1">
<option selected="selected">Choose one</option>
<?php
foreach($names as $name) { ?>
<option value="<?= $name['name'] ?>"><?= $name['name'] ?></option>
<?php
} ?>
</select>
$names is example array take your.
check this link also
How to create checkbox inside dropdown?
Note
Okay, I can provide you a pseudo-code to help get you started. I borrowed my code from my own web server along with code from CodePen. Please note that I did not test the code, so do feel free to modify the code.
Code
PHP
<div class="dropdown" data-control="checkbox-dropdown">
<label class="dropdown-label">Select categories.</label>
<ul class="article-category-list dropdown-list">
<?php if(count($categories) > 0) {
foreach ($categories as $category) { ?>
<li class="article-category-listitem dropd-wn-listoption">
<input name="cbcategories[]"
id="cb<?=$category["CategoryID"] ?>" type="checkbox"
class="article-list-cb"
value="<?=$category['CategoryID'] ?>" />
<label class="article-list-lbl"
for="cb<?=$category["CategoryID"] ?>">
<?=$category['CategoryName'] ?>
</label>
</li>
<?php }} ?>
</ul>
</div>
This is a code borrowed from the administration portion of my blog that I haven't gotten into website development for a long time.
So the $categories variable is a list of categories for a blog. If the $categories array is greater than 0, PHP will loop through the $categories and will write out HTML code inside an unordered list, which contains the ID and name of the category.
CSS
(Borrowed from CodePen)
.dropdown {
position: relative;
font-size: 14px;
color: #333;
.dropdown-list {
padding: 12px;
background: #fff;
position: absolute;
top: 30px;
left: 2px;
right: 2px;
box-shadow: 0 1px 2px 1px rgba(0, 0, 0, .15);
transform-origin: 50% 0;
transform: scale(1, 0);
transition: transform .15s ease-in-out .15s;
max-height: 66vh;
overflow-y: scroll;
}
.dropdown-option {
display: block;
padding: 8px 12px;
opacity: 0;
transition: opacity .15s ease-in-out;
}
.dropdown-label {
display: block;
height: 30px;
background: #fff;
border: 1px solid #ccc;
padding: 6px 12px;
line-height: 1;
cursor: pointer;
&:before {
content: '▼';
float: right;
}
}
&.on {
.dropdown-list {
transform: scale(1, 1);
transition-delay: 0s;
.dropdown-option {
opacity: 1;
transition-delay: .2s;
}
}
.dropdown-label:before {
content: '▲';
}
}
[type="checkbox"] {
position: relative;
top: -1px;
margin-right: 4px;
}
}
It looks to me the "&.on" class is for when dropdown is opened.
jQuery
Now this code is in jQuery format. If you want plain JavaScript code, let me know.
(function($) {
var CheckboxDropdown = function(el) {
var _this = this;
this.isOpen = false;
this.areAllChecked = false;
this.$el = $(el);
this.$label = this.$el.find('.dropdown-label');
this.$checkAll = this.$el.find('[data-toggle="check-all"]').first();
this.$inputs = this.$el.find('[type="checkbox"]');
this.onCheckBox();
this.$label.on('click', function(e) {
e.preventDefault();
_this.toggleOpen();
});
this.$checkAll.on('click', function(e) {
e.preventDefault();
_this.onCheckAll();
});
this.$inputs.on('change', function(e) {
_this.onCheckBox();
});
};
CheckboxDropdown.prototype.onCheckBox = function() {
this.updateStatus();
};
CheckboxDropdown.prototype.updateStatus = function() {
var checked = this.$el.find(':checked');
this.areAllChecked = false;
this.$checkAll.html('Check All');
if(checked.length <= 0) {
this.$label.html('Select Options');
}
else if(checked.length === 1) {
this.$label.html(checked.parent('label').text());
}
else if(checked.length === this.$inputs.length) {
this.$label.html('All Selected');
this.areAllChecked = true;
this.$checkAll.html('Uncheck All');
}
else {
this.$label.html(checked.length + ' Selected');
}
};
CheckboxDropdown.prototype.onCheckAll = function(checkAll) {
if(!this.areAllChecked || checkAll) {
this.areAllChecked = true;
this.$checkAll.html('Uncheck All');
this.$inputs.prop('checked', true);
}
else {
this.areAllChecked = false;
this.$checkAll.html('Check All');
this.$inputs.prop('checked', false);
}
this.updateStatus();
};
CheckboxDropdown.prototype.toggleOpen = function(forceOpen) {
var _this = this;
// The dropdown menu is opened.
if(!this.isOpen || forceOpen) {
this.isOpen = true;
this.$el.addClass('on');
$(document).on('click', function(e) {
if(!$(e.target).closest('[data-control]').length) {
_this.toggleOpen();
}
});
}
else {
// The dropdown menu is closed.
this.isOpen = false;
this.$el.removeClass('on');
$(document).off('click');
}
};
var checkboxesDropdowns = document.querySelectorAll('[data-control="checkbox-dropdown"]');
for(var i = 0, length = checkboxesDropdowns.length; i < length; i++) {
new CheckboxDropdown(checkboxesDropdowns[i]);
}
})(jQuery);
I'm not sure why a "_this" variable is needed, plus I'm not an expert in CSS regarding the use of "&" character such as "&.on" (looks to me like a nested class or something), but at least I can be of help.
Here's the source of the code borrowed from CodePen (some from HTML such as dropdown-list):
https://codepen.io/RobotsPlay/pres/pyNLdL
Update as of 2:15 AM EDT:
As a fallback, for those who turned off JavaScript or is using a NoScript extension in Firefox to browse the web safely, you might want to provide just a simple <select><option>...</option></select> code as provided by Tejas kothari's answer and wrap it in a <noscript>...</noscript> tag.
Example of <noscript> tag:
<noscript>
<label for="categories_noscript">
Categories:
</label>
<p>In Windows/Linux, do Ctrl+click or in macOS, do Cmd+click to select
more than one.</p>
<select name="categories_noscript[]" id="categories_noscript">
<option selected="selected">Choose one or more categories</option>
<?php if(count($categories) > 0) {
foreach($categories as $category) { ?>
<option value="<?=$category['CategoryID'] ?>">
<?=$category['CategoryName'] ?>
</option>
</select>
</noscript>
It's not a drop down combo box as provided in the code above, but at least people can submit a form with JavaScript disabled.
Related
I am using the following code to show search results. It has two options, one is a text field and another is a dropdown select option. I would like to convert the dropdown field into a checkbox option and allow users to select more than 1 option at a time. How can I do that?
<script>
$(document).ready(function(){
load_data(1);
function load_data(page,query,city)
{
$.ajax({
url:"fetch_data.php",
method:"POST",
data:{page:page, query:query, city:city},
success:function(data)
{
$('#dynamic_content').html(data);
}
});
}
$(document).on('click', '.page-link', function(){
var page = $(this).data('page_number');
var query = $('#search_box').val();
var city = $('#city_box').val();
load_data(page, query, city);
});
$('#search_box').keyup(function () {
var query = $('#search_box').val();
var city = $('#city_box').val();
load_data(1, query, city);
});
$('#city_box').change(function () {
var query = $('#search_box').val();
var city = $('#city_box').val();
load_data(1, query, city);
});
});
</script>
Current dropdown example:
<form action="" class="row login_form">
<select name="city_box" id="city_box">
<option value="newyork">New York</option>
<option value="london">London</option>
<option value="tokyo">Tokyo</option>
<option value="paris">Paris</option>
</select>
</form>
As per your query there are lot of stuff available. I have used Select2.js. This having so many features. I tried some way to achieve you scenario. Try below code snippet will work for you.
$(function() {
$("#multiple").select2({
closeOnSelect : false,
placeholder : "Placeholder",
allowHtml: true,
allowClear: true,
tags: true
});
});
function iformat(icon, badge,) {
var originalOption = icon.element;
var originalOptionBadge = $(originalOption).data('badge');
return $('<span><i class="fa ' + $(originalOption).data('icon') + '"></i> ' + icon.text + '<span class="badge">' + originalOptionBadge + '</span></span>');
}
.select2-container {
min-width: 400px;
}
.select2-results__option {
padding-right: 20px;
vertical-align: middle;
}
.select2-results__option:before {
content: "";
display: inline-block;
position: relative;
height: 20px;
width: 20px;
border: 2px solid #e9e9e9;
border-radius: 4px;
background-color: #fff;
margin-right: 20px;
vertical-align: middle;
}
.select2-results__option[aria-selected=true]:before {
font-family:fontAwesome;
content: "\f00c";
color: #fff;
background-color: #f77750;
border: 0;
display: inline-block;
padding-left: 3px;
}
.select2-container--default .select2-results__option[aria-selected=true] {
background-color: #fff;
}
.select2-container--default .select2-results__option--highlighted[aria-selected] {
background-color: #eaeaeb;
color: #272727;
}
.select2-container--default .select2-selection--multiple {
margin-bottom: 10px;
}
.select2-container--default.select2-container--open.select2-container--below .select2-selection--multiple {
border-radius: 4px;
}
.select2-container--default.select2-container--focus .select2-selection--multiple {
border-color: #f77750;
border-width: 2px;
}
.select2-container--default .select2-selection--multiple {
border-width: 2px;
}
.select2-container--open .select2-dropdown--below {
border-radius: 6px;
box-shadow: 0 0 10px rgba(0,0,0,0.5);
}
.select2-selection .select2-selection--multiple:after {
content: 'hhghgh';
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.6-rc.0/js/select2.min.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.6-rc.0/css/select2.min.css" rel="stylesheet" />
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
<h3>Multiple Select with Checkboxes</h3>
<select id="multiple" class="js-select2" multiple>
<option>Java</option>
<option>Javascript</option>
<option>PHP</option>
<option>Visual Basic</option>
</select>
I have an AJAX HTML page and a submit PHP page, which sends data from SQL to update HTML on page.
I have a list of films within a PHPMyAdmin MariaDB table. One of the columns is "channel". Channel will either say "NOWTV", "BBC", or "SKYTV". I want the user to be able to select the channel and for this to update.
If I check the array for 1 string - for example: skytv, the SQL pulls the data. However, if I want to change the WHERE clause, based on selection - the filtering does not work.
I've tried ".=where OR" to change the channel selection.
ajax.html
<html>
<style>
body {
padding: 10px;
}
h2 {
margin: 1em 0 0.3em 0;
color: #343434;
font-weight: normal;
font-size: 30px;
line-height: 40px;
font-fnuamily: 'Orienta', sans-serif;
}
#employees {
font-family: "Lucida Sans Unicode","Lucida Grande",Sans-Serif;
font-size: 12px;
background: #fff;
margin: 10px 10px 0 0;
border-collapse: collapse;
text-align: center;
float: left;
width: 100%;
}
#employees th {
font-size: 14px;
font-weight: normal;
color: #039;
padding: 4px 4px;
border-bottom: 1px solid #6678b1;
}
#employees td {
border-bottom: 1px solid #ccc;
color: #669;
padding: 8px 10px;
}
#employees tbody tr:hover td {
color: #009;
}
.slidecontainer {
width: 50%; /* Width of the outside container */
}
/* The slider itself */
.slider {
-webkit-appearance: none; /* Override default CSS styles */
appearance: none;
width: 50%; /* Full-width */
height: 25px; /* Specified height */
background: #d3d3d3; /* Grey background */
outline: none; /* Remove outline */
opacity: 0.7; /* Set transparency (for mouse-over effects on hover) */
-webkit-transition: .2s; /* 0.2 seconds transition on hover */
transition: opacity .2s;
}
/* Mouse-over effects */
.slider:hover {
opacity: 1; /* Fully shown on mouse-over */
}
.slider::-webkit-slider-thumb {
-webkit-appearance: none; /* Override default look */
appearance: none;
width: 25px; /* Set a specific slider handle width */
height: 25px; /* Slider handle height */
background: #000000; /* Square background */
cursor: pointer; /* Cursor on hover */
}
.slider::-moz-range-thumb {
width: 25px; /* Set a specific slider handle width */
height: 25px; /* Slider handle height */
background: #4CAF50; /* Green background */
cursor: pointer; /* Cursor on hover */
}
</style>
</head>
<body>
<input type="checkbox" id="nowtv" name="nowtv" >
<label for="nowtv">Now TV</label>
</div>
<div>
<input type="checkbox" id="skytv" name="skytv" >
<label for="skytv">Sky Movies</label>
</div>
<div>
<input type="checkbox" id="iplayer" name="iplayer" >
<label for="iplayer">BBC iPlayer</label>
</div>
<h2>Max Run-Time:</h2>
<div class="slidecontainer">
<input type="range" min="0" max="200" value="0" class="slider" id="runtime">
<p>Runtime: <span id="runtime_"></span></p>
</div>
<table id="employees">
<tbody>
</tbody>
</table>
<script>
var slider = document.getElementById("runtime");
var output = document.getElementById("runtime_");
output.innerHTML = slider.value;
slider.oninput = function() {
output.innerHTML = this.value;
}
/script>
</div>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<p id="record_count"></p>
<script>
function makeTable(data){
var tbl_body = "";
for (var i = 0; i < data.length; i++)
{
var tbl_row = "";
var t = i;
for (var j=0; j<4; j++)
{
//tbl_row +=("<td>" + data[i].tmdbid + "</td>");
tbl_row +=("<td><a href='new/" + data[i].tmdbid + "'><IMG SRC='webaddress"+ data[i].poster +"'></a></td>");
i++;
}
tbl_body += "<tr>"+tbl_row+"</tr>"
}
return tbl_body;
}
function getEmployeeFilterOptions(){
var opts = {
checkboxes: [],
sliderValue: null
};
$checkboxes.each(function(){
if(this.checked){
opts.checkboxes.push(this.name);
}
});
var slider = document.getElementById("runtime");
opts.sliderValue = slider.value;
return opts;
}
function updateEmployees(opts){
$.ajax({
type: "POST",
url: "submit.php",
dataType : 'json',
cache: false,
data: opts,
success: function(records){
console.log(records);
$('#employees tbody').html(makeTable(records));
}
});
}
var $checkboxes = $("input");
$checkboxes.on("change", function(){
var opts = getEmployeeFilterOptions();
updateEmployees(opts);
});
</script>
</body>
</html>
submit.php
<?php
$pdo = new PDO(
'mysql:host=xxxxxxxx;dbname=xxxxxxxx', 'xxxxxxxx', 'xxxxxxxx'
);
$checkboxes = $_POST["checkboxes"];
$slider_value = $_POST["sliderValue"];
$select = 'SELECT *';
$from = ' FROM streaming';
$where = ' WHERE poster <>"" AND runtime <' . $slider_value . ' AND channel = "X" ';
if (in_array("nowtv", $checkboxes))
{
$where .= ' OR channel = "NOWTV" ';
}
if (in_array("skytv", $checkboxes))
{
$where .= ' OR channel = "SKYTV" ';
}
if (in_array("iplayer", $checkboxes))
{
$where .= ' OR channel = "BBC" ';
}
$sql = $select . $from . $where;
$statement = $pdo->prepare($sql);
$statement->execute();
$results = $statement->fetchAll(PDO::FETCH_ASSOC);
$json = json_encode($results);
echo($json);
>
The output I am expecting is for the user to be able to select the checkboxes and runtime - to then update the films available.
The current output shows nothing. :(
In my case of studies, I must to create an autocomplete search with this script. My problem is how to call the database. I don't know.
I suppose I must create another file call search.php
My code
<head>
<script src="https://cdn.jsdelivr.net/gh/nextapps-de/flexsearch#master/dist/flexsearch.min.js"></script>
<script src="search.php"></script>
<style>
table{
width: 300px;
table-layout: fixed;
}
td, tr{
border: none;
}
input{
border: 1px solid #ddd;
border-radius: 3px;
outline: none;
background-color: #f5f5f5;
}
input, div{
padding:5px 5px;
width: 100%;
box-sizing: border-box;
}
#suggestions div{
padding: 10px 0;
border-bottom: 1px solid #ddd;
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
}
</style>
</head>
<div><input type="text" placeholder="Search ..." onkeyup="show_results.call(this);"></div>
<div id="suggestions"></div>
</div>
<script>
(function(){
var index = new FlexSearch({
encode: "advanced",
tokenize: "reverse",
suggest: true
});
var container = document.getElementById("suggestions");
for(var i = 0; i < data.length; i++){
index.add(i, data[i]);
}
window.show_results = function(){
var results = index.search(this.value, 10);
var fragment = document.createDocumentFragment();
var entry, tmp;
for(var i = 0; i < results.length; i++){
entry = document.createElement("div");
entry.textContent = data[results[i]];
fragment.appendChild(entry);
}
while((tmp = container.firstChild)){
container.removeChild(tmp)
}
container.appendChild(fragment);
};
}());
</script>
my search.php, I tried this code, but on how to take the seach keywords make by someone.
<?php
$terms = strtolower($_GET["q"]);
$Qcheck = $Db->prepare('select distinct products_id as id,
products_description as description
from :table_products_description
where products_description LIKE :terms
limit 10
');
$Qcheck->bindValue(':terms', '%' . $terms . '%');
$Qcheck->execute();
$list = $Qcheck->rowCount() ;
if ($list > 0) {
$array = [];
while ($value = $Qcheck->fetch() ) {
$array[] = $value;
}
$json_response = json_encode($array);
echo $json_response;
?>
I expect inside the input field the search result across the database
I would like to help you. First of all I cannot check your php code, so please check the php returns a json encoded string. Then the solution to your intend is as follow.
Replace the last line in search.php by these two:
header('Content-Type: text/javascript');
echo 'var data = ' . $json_response . ';';
That's all :)
So, i have forms and php code. I know how change form with button click
(by the way, animation does not work if the button is in the form. But if the button in outside of the form, it works, but it doesn't matter.)
Like this
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js">
$('#btn_1').click(function(){
$('#formsss').toggleClass('flipped')
});
</script>
But I do not know how to make the animation turn on through the condition code in php
<div id="formsss">
<div id="form_1">
<h3>Form 1</h3><br>
<form action="" method="POST">
<input name="input1" value="<?php echo $_POST[input1]; ?>">
<br>
<?php
if ( isset($_POST['clicked_btn_1']) )
{
$errors = array();
if (trim($_POST['input1'] == ''))
{
$errors[] = 'Enter text';
}
if (R::count('test', 'input1 = ?', array($_POST['input1'])) > 0)
{
$errors[] = 'Such data is already in the database';
}
if (empty($errors))
{
// SWITCH ON FORM 2 .... HOW?????
session_start();
$_SESSION['input1'] = $_POST['input1'];
}
else
{
echo '<div style="color: red;">'.array_shift($errors).'</div>';
}
}
?>
<button id="btn_1" type="submit" name="clicked_btn_1">Button 1</button>
</form>
</div>
<div id="form_2">
<h3>Form 2</h3><br>
<form action="" method="POST">
<input name="input2" value="<?php echo $_POST[input2]; ?>"><br>
<?php
if ( isset($_POST['clicked_btn_2']) )
{
$errors = array();
if (trim($_POST['input2'] == ''))
{
$errors[] = 'Enter text';
}
if (R::count('test', 'input2 = ?', array($_POST['input2'])) > 0)
{
$errors[] = 'Such data is already in the database';
}
if (empty($errors))
{
// put in a database of two forms
$test = R::dispense('test');
$test->input1 = $_SESSION['input1'];
$test->input2 = $_POST['input2'];
R::store($test);
}
else
{
echo '<div style="color: red;">'.array_shift($errors).'</div>';
}
}
?>
<button id="btn_2" type="submit" name="clicked_btn_2">Button 2</button>
</form>
</div>
</div>
css animation
#form_2{
-moz-transform: rotateY(-180deg)scale(.1)translateY(-70px);
-webkit-transform: rotateY(-180deg)scale(.1)translateY(-70px);
-o-transform: rotateY(-180deg)scale(.1)translateY(-70px);
transform: rotateY(-180deg)scale(.1)translateY(-70px);
filter: alpha(opacity=0);
opacity: 0;
z-index: 1;
}
#form_2, #form_1 {
-moz-transform-style: preserve-3d;
-webkit-transform-style: preserve-3d;
-o-transform-style: preserve-3d;
transform-style: preserve-3d;
-moz-backface-visibility: hidden;
-webkit-backface-visibility: hidden;
-o-backface-visibility: hidden;
backface-visibility: hidden;
-moz-transition: .6s;
-webkit-transition: .6s;
-o-transition: .6s;
transition: 600ms 0ms;
transition-delay: 0.1s;
-o-transition-delay: 0.1s;
-webkit-transition-delay: 0.1s;
-moz-transition-delay: 0.1s;
}
#form_2 {
bottom: 20px;
top: 359px;
left: 20px;
right: 20px;
}
#form_2, pre {
position: absolute;
}
/*************************************************/
.flipped#formsss {
overflow: hidden;
}
.flipped #form_1 {
-moz-transform: rotateY(180deg)scale(.7);
-webkit-transform: rotateY(180deg)scale(.7);
-o-transform: rotateY(180deg)scale(.7);
transform: rotateY(180deg)scale(.7);
filter: alpha(opacity=0);
opacity: 0;
}
.flipped #form_2 {
-moz-transform: rotateY(0)scale(1);
-webkit-transform: rotateY(0)scale(1);
-o-transform: rotateY(0)scale(1);
transform: rotateY(0)scale(1);
filter: alpha(opacity=100);
opacity: 1;
z-index: 5;
display: block;
}
To trigger the flip annimation on startup just add the bellow script output inside the condition inisde the php code :
if (empty($errors)) {
session_start();
$_SESSION['input1'] = $_POST['input1'];
// SWITCH ON FORM 2 .... HOW ?? , bellow code will switch :)
echo "<script type='text/javascript'>";
//the above will be executed after dom load
echo "$( function(){ $('#formsss').toggleClass('flipped'); })";
echo "</script>";
}
I have 4 dependent search dropdown menues next to each other. I have two issues:
When I press a key in any of the drop-menues, the mysql-connected lists drop but not underneath the actual 'input-type-search-box'.
Also when I e.g. press a key in the first menue, the other menues move underneath the dropped list but the menues/'input-type-search-boxes' shall actually remain fixed next to each other.
This might only be a simple css-issue, but I cant get it work for quite a while now trying many things, so I posted it. Thanks for your help!
Here is the code: HTML
<input type="text" class="autosuggest" id="autosuggest1" placeholder="Select Continent...">
<div class="type">
<ul class="result" id="result1"></ul>
</div>
<input type="text" class="autosuggest" id="autosuggest2" placeholder="Select Country...">
<div class="type">
<ul class="result" id="result2"></ul>
</div>
<input type="text" class="autosuggest" id="autosuggest3" placeholder="Select Area...">
<div class="type">
<ul class="result" id="result3"></ul>
</div>
<input type="text" class="autosuggest" id="autosuggest4" placeholder="Select Category...">
<div class="type">
<ul class="result" id="result4"></ul>
</div>
CSS
#search_line{
margin-top: 20px;
display: inline;
}
.autosuggest, .type, .result{
width: 150px;
}
#autosuggest1{
padding: 4px;
border: 1px solid blue;
background: white;
float: left;
}
#autosuggest2{
padding: 4px;
border: 1px solid blue;
background: white;
float: left;
}
#autosuggest3{
padding: 4px;
border: 1px solid blue;
background: white;
float: left;
}
#autosuggest4{
padding: 4px;
border: 1px solid blue;
background: white;
float: left;
}
.result{
width: 150px;
list-style: none;
}
.result li{
padding:5px;
border:1px solid #000;
border-top: 0;
cursor: pointer;
}
JS
$(document).ready(function() {
$('#autosuggest1').keyup(function() {
var continent = $(this).attr('value');
$.post('php/dropdown.php', {continent:continent}, function(data) {
$('#result1').html(data);
$('.result li').click(function() {
var result_value = $(this).text();
$('#autosuggest1').attr('value', result_value);
$('#result1').html('');
});
});
});
$('#autosuggest2').keyup(function() {
var country = $(this).attr('value');
$.post('php/dropdown.php', {country:country}, function(data) {
$('#result2').html(data);
$('.result li').click(function() {
var result_value = $(this).text();
$('#autosuggest2').attr('value', result_value);
$('#result2').html('');
});
});
});
$('#autosuggest3').keyup(function() {
var area = $(this).attr('value');
$.post('php/dropdown.php', {area:area}, function(data) {
$('#result3').html(data);
$('.result li').click(function() {
var result_value = $(this).text();
$('#autosuggest3').attr('value', result_value);
$('#result3').html('');
});
});
});
$('#autosuggest4').keyup(function() {
var category = $(this).attr('value');
$.post('php/dropdown.php', {category:category}, function(data) {
$('#result4').html(data);
$('.result li').click(function() {
var result_value = $(this).text();
$('#autosuggest4').attr('value', result_value);
$('#result4').html('');
$('#result4').focusout('');
});
});
});
});
And here also PHP
<?php
include '../core/db/connectdropdown.php';
if (isset($_POST['continent']) == true && empty($_POST['continent']) == false) {
$continent = mysql_real_escape_string($_POST['continent']);
$query = mysql_query("SELECT DISTINCT `continent` FROM `area` WHERE `continent` LIKE '$continent%'");
while (($row = mysql_fetch_assoc($query)) !== false) {
echo '<li>', $row['continent'], '</li>';
}
}
if (isset($_POST['country']) == true && empty($_POST['country']) == false) {
$country = mysql_real_escape_string($_POST['country']);
$query = mysql_query("SELECT DISTINCT `country` FROM `area` WHERE `country` LIKE '$country%'");
while (($row = mysql_fetch_assoc($query)) !== false) {
$dbcountry = $row['country'];
}
}
if (isset($_POST['area']) == true && empty($_POST['area']) == false) {
$area = mysql_real_escape_string($_POST['area']);
$query = mysql_query("SELECT DISTINCT `area` FROM `area` WHERE `area` LIKE '$area%'");
while (($row = mysql_fetch_assoc($query)) !== false) {
echo '<li>', $row['area'], '</li>';
}
}
if (isset($_POST['category']) == true && empty($_POST['category']) == false) {
$category = mysql_real_escape_string($_POST['category']);
$query = mysql_query("SELECT `category` FROM `categories` WHERE `category` LIKE '$category%'");
while (($row = mysql_fetch_assoc($query)) !== false) {
echo '<li>', $row['category'], '</li>';
}
}
?>
It sounds like you might have some JavaScript problems as well. Is your script appending the results for the list by ID or by class? Just curious.
I'm not seeing any apparent problems with the CSS and HTML you posted but I tried changing the HTML and CSS structure a bit in this fiddle. Maybe it improves things for you:
http://jsfiddle.net/w8zG6/
What happens if you use my CSS/HTML. Do you get better results? (worse perhaps?)
If this isn't helping could you post your JavaScript that handles creating the menus?
Edit:
There seems like there might be a problem in your PHP:
In your other Ajax handler code blocks you have this:
echo '<li>', $row['continent'], '</li>';
Whereas your country handling code has this:
$dbcountry = $row['country'];
Try replacing that line with the following:
echo '<li>', $row['country'], '</li>';