How can I get a value from a personalized dropdown? - php

All the people use the normal dropdown like:
<form>
<select>
<option> bla bla </option>
</select>
</form>
Like that I can get the selected value trough PHP. But if I use divs I can't get the values from the multiple dropdowns.
function select_best_plan(sel, _this) {
$parent = $(_this).closest('.select-general');
$parent.find('button font').html($(_this).find('font').html());
$parent.find('.select-menu .select-menu-option').removeClass('active');
$(_this).addClass('active');
}
.select-general {
display: inline-block;
overflow: hidden;
border-radius: 12px;
vertical-align: middle;
position: relative;
text-transform: uppercase;
background: #182045;
color: #FFFFFF;
width: 170px;
min-width: 160px;
text-align: left;
font-size: 15px;
max-width: 100%;
}
.select-general .select-button {
text-align: right;
font-size: 13px;
height: 38px;
line-height: 38px;
padding: 0px 13px;
border-radius: 12px;
color: #FFFFFF;
width: 100%;
}
.select-general .select-button font {
text-align: left;
width: calc(100% - 20px);
height: 100%;
overflow: hidden;
max-width: 340px;
text-overflow: ellipsis;
white-space: nowrap;
}
.select-general .select-menu {
padding: 0px;
overflow: hidden;
max-height: 0;
transition: max-height 0.15s ease-out, padding 0.15s ease-out;
}
.select-general .select-menu-option {
text-align: right;
font-size: 13px;
height: 38px;
line-height: 38px;
padding: 0px 13px;
color: #FFFFFF;
width: calc(100% - 26px);
cursor: pointer;
}
.select-general .select-menu-option font {
text-align: left;
}
.select-general .select-menu-option:hover {
background: #1A2A74;
}
.select-general .select-menu-option.active {
opacity: 0.5;
}
.select-general:hover .select-menu {
padding: 10px 0px;
max-height: 500px;
transition: max-height 0.15s ease-in, padding 0.15s ease-in;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="select-general" style="width: 250px;">
<button class="select-button">
<font class="float-left">Quantos Utilizadores Quer?</font><i class="icon small caret down"></i>
</button>
<div class="select-menu">
<div class="select-menu-option" data="1" onclick="select_best_plan(6, this)">
<font class="float-left">Apenas 1</font>
</div>
<div class="select-menu-option" data="3" onclick="select_best_plan(7, this)">
<font class="float-left">Até 3</font>
</div>
<div class="select-menu-option" data="5" onclick="select_best_plan(8, this)">
<font class="float-left">Até 5</font>
</div>
<div class="select-menu-option" data="10" onclick="select_best_plan(9, this)">
<font class="float-left">Até 10</font>
</div>
<div class="select-menu-option" data="15" onclick="select_best_plan(10, this)">
<font class="float-left">Até 15</font>
</div>
</div>
</div>
My idea is that the people select the first div "Apenas 1" and on submit I get that values on PHP.
I really can't find any tips that can help me or I'm just newbie on this..
Thanks.

Just add <input type="hidden" name="select" id="hidden-select" />
Change <div class="select-menu-option" data="5" to ... data-val="5"
and in: select_best_plan add
$('#hidden-select').val($(_this).data('val'))

There is lot of content available online explaining a lot of ways to implement this kind of a behavior.
One such link -
How to use FormData for ajax file upload
Set value of hidden field in a form using jQuery's ".val()" doesn't work
For more ways of implementation you can google with these key words -
Ajax calls
Submitting form with hidden input fields
How to build and submit Form using FormData. etc

Sorry for the first answer.
Well if you want to use customize select then use JavaScript to get the data. Normally only input tags select can be post or send automatically by form tag.
The submit button triggers a JavaScript function then get the value of the selected div then create a input tag containing the value of the div.
Ex:
<div class="select-general" style="width: 250px;">
<button class="select-button">
<font class="float-left">Quantos Utilizadores Quer?</font><i class="icon small caret down"></i>
</button>
<div class="select-menu">
<div class="select-menu-option" data="1" onclick="select_best_plan(6, this)">
<font class="float-left">Apenas 1</font>
</div>
function getselectedval(){
var data = $("div selected identifier here").attr("data");
$("container of passing input").append('<input name="name" val="'+ data +'" type="hidden">');
//submit the form
$("your form").submit();
}
This seems to be a cheat but hope this helps.

Related

how can I make my search bar look for a keyword in my database and display it on my webpage

I want to make this form to search for a keyword in my database that display and highlight it in my webpage with that specific words that is typed in the search bar. purpose of this code is a FAQ for a web-app I'm developing
<form>
<input type="text" placeholder="Search..." style=" flex: 1; padding: 12px 20px; margin: 8px 0; box-sizing: border-box; border: 2px solid #ccc; border-radius: 4px; width: 70%;">
<input type="submit" value="Search" style=" width: auto; padding: 10px 18px; background-color: #4CAF50; color: white; margin: 8px 0; border: none; border-radius: 4px; cursor: pointer;">
</form>
#foreach($kb_info as $kb_info)
<div class=" {{$kb_info->kb_category}}">
<a href="/adminkbView/{{$kb_info->kb_ID}}" class="card content {{$kb_info->kb_category}}" id="content clickable" style="margin: 1%; cursor: pointer; text-decoration: none; color: black;">
<div class="card-header">
{{$kb_info->kb_title}}
</div>
<div class="card-body">
<blockquote class="blockquote mb-0">
<p>{{$kb_info->kb_content}}</p>
<footer class="blockquote-footer">{{$kb_info->kb_resolution}}<cite title="Source Title"></cite></footer>
</blockquote>
</div>
</a>
</div>
#endforeach
attached image is the preview of my web-page
I tried using this script and it does nothing.
const form = document.getElementById('search-form');
const input = document.getElementById('search-input');
form.addEventListener('submit', function(event) {
event.preventDefault();
console.log(`Searching for: ${input.value}`);
// Add your search functionality here
});

How to create a slider diagram for a webpage?

I would like to create a slider diagram like this for my webpage to display results:
How can I do this provided I have a maximum and minimum and the value I would like to plot? Prefereably, I would like to create it on-the-fly as I generate the result page using html/javascript/php.
EDIT:
I can see that my question was confusing. I do not want to create a slider (like an input to a form form) but an output diagram that has a vertical line at a fixed value with a colour gradient background.
Thank you for any answers!
<html>
<style>
#slidecontainer {
width: 100%;
}
.slider {
-webkit-appearance: none;
width: 100%;
height: 25px;
background: #d3d3d3;
outline: none;
opacity: 0.7;
-webkit-transition: .2s;
transition: opacity .2s;
}
.slider:hover {
opacity: 1;
}
.slider::-webkit-slider-thumb {
-webkit-appearance: none;
appearance: none;
width: 25px;
height: 25px;
background: #4CAF50;
cursor: pointer;
}
.slider::-moz-range-thumb {
width: 25px;
height: 25px;
background: #4CAF50;
cursor: pointer;
}
</style>
<body>
<div id="slidecontainer">
<input type="range" min="1" max="100" value="50" class="slider" id="myRange">
</div>
</body>
</html>
here you have a slider, enjoy!
Since you want min-max value you need to create 2 range slider.
Check snippet
below.
var rangeSlider = function(){
var slider = $('.range-slider'),
range = $('.range-slider__range'),
value = $('.range-slider__value');
slider.each(function(){
value.each(function(){
var value = $(this).prev().attr('value');
$(this).html(value);
});
range.on('input', function(){
$(this).next(value).html(this.value);
});
});
};
rangeSlider();
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="range-slider">
<label>Min.</label>
<input class="range-slider__range" type="range" value="100" min="0" max="500">
<span class="range-slider__value">0</span>
</div>
<div class="range-slider">
<label>Max.</label>
<input class="range-slider__range" type="range" value="250" min="0" max="500" step="50">
<span class="range-slider__value">0</span>
</div>
And If you want save space you can create 1 range slider with 2 control slider.
Create a html for range slider then apply some jquery.
Please check snippet below
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.css" media="screen">
<script src="https://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js"></script>
<div data-role="rangeslider">
<label for="price-min">Price:</label>
<input type="range" name="price-min" id="price-min" value="200" min="0" max="1000">
<label for="price-max">Price:</label>
<input type="range" name="price-max" id="price-max" value="800" min="0" max="1000">
</div>
Then if you want to submit data to db you need to create form for this
Reference for range slider : https://www.w3schools.com/howto/howto_js_rangeslider.asp
I hope this answer can help.
At last, I've got it. Just HTML and CSS (and PHP if I want to be able to dynamically assign the vertical line by using style="left:x%")
.grad {
background: linear-gradient(to right, rgba(185, 74, 72, 0.75), rgba(192, 152, 83,0.25), rgba(70, 136, 71,0.75));
width: 100px;
height: 15px;
border-radius: 24px;
border-color: #446e9b;
border-width: 1px;
}
.vertical-line {
width: 1px;
height: 15px;
border-left: 2px solid #446e9b;
position: relative;
top: 0;
background: none;
}
.tick {
width: 1px;
height: 5px;
border-left: 1px solid #999999;
position: relative;
top: 0;
background: none;
}
.bottom-tick {
margin-top: -5px;
}
.top-tick{
margin-top: -5px;
}
.inner10{
z-index: 10;
}
.inner2{
z-index: 2;
left: 20%;
margin-top: -15px;
}
.inner3{
z-index: 3;
left: 40%;
}
.inner4{
z-index: 4;
left: 60%;
}
.inner5{
z-index: 5;
left: 80%;
}
.inner6{
z-index: 6;
left: 20%;
}
.inner7{
z-index: 7;
left: 40%;
}
.inner8{
z-index: 8;
left: 60%;
}
.inner9{
z-index: 9;
left: 80%;
}
<div class="grad">
<div class='vertical-line inner10' style="left:35%"></div>
<div class='tick inner6 bottom-tick'></div>
<div class='tick inner7 bottom-tick'></div>
<div class='tick inner8 bottom-tick'></div>
<div class='tick inner9 bottom-tick'></div>
<div class='tick inner2'></div>
<div class='tick inner3 top-tick'></div>
<div class='tick inner4 top-tick'></div>
<div class='tick inner5 top-tick'></div>
</div>

Results fixed on webpage

When I try to display content from another blade template, it will only show certain data on the webpage. What I want is inside this page, the content from test.blade.php together with the button, when click will pop up a form(I don't want the test.blade.php content to be inside). But whenever I try to do it, only certain information is shown and when I view page source, all the data has already been loaded. I have asked this question before already and someone told me it was the fault of my css, but I when I try to look at it, I don't really see anything which is causing this to happen. Can someone help me please? Thanks in advance!
I will put the screenshot here first in the question.
This is what it is suppose to look like where it will have a scroll down bar, and below there should be a button for the popup form.
But this is what I am getting (I have checked that all the data are already loaded)
elements.css (here is the css that I used)
#abc {
width: 100%;
height: 100%;
opacity: .95;
top: 0;
left: 0;
display: none;
position: fixed;
background-color: #313131;
overflow: auto;
}
img#close {
position: absolute;
right: -14px;
top: -14px;
cursor: pointer;
}
div#popupContact {
position: absolute;
left: 50%;
top: 17%;
margin-left: -202px;
font-family: 'Raleway', sans-serif;
}
form {
max-width: 300px;
min-width: 250px;
padding: 10px 50px;
border: 2px solid gray;
border-radius: 10px;
font-family: raleway;
background-color: #fff;
}
p {
margin-top: 30px;
}
h2 {
background-color: #FEFFED;
padding: 20px 35px;
margin: -10px -50px;
text-align: center;
border-radius: 10px 10px 0 0;
}
hr {
margin: 10px -50px;
border: 0;
border-top: 1px solid #ccc;
}
input[type=text] {
width: 82%;
padding: 10px;
margin-top: 30px;
border: 1px solid #ccc;
padding-left: 40px;
font-size: 16px;
font-family: raleway;
}
#name {
background-image: url(../images/name.jpg);
background-repeat: no-repeat;
background-position: 5px 7px;
}
#email {
background-image: url(../images/email.png);
background-repeat: no-repeat;
background-position: 5px 7px;
}
textarea {
background-image: url(../images/msg.png);
background-repeat: no-repeat;
background-position: 5px 7px;
width: 82%;
height: 95px;
padding: 10px;
resize: none;
margin-top: 30px;
border: 1px solid #ccc;
padding-left: 40px;
font-size: 16px;
font-family: raleway;
margin-bottom: 30px;
}
#submit {
text-decoration: none;
width: 100%;
text-align: center;
display: block;
background-color: #FFBC00;
color: #fff;
border: 1px solid #FFCB00;
padding: 10px 0;
font-size: 20px;
cursor: pointer;
border-radius: 5px;
}
span {
color: red;
font-weight: 700;
}
button {
width: 10%;
height: 45px;
border-radius: 3px;
background-color: #cd853f;
color: #fff;
font-family: 'Raleway', sans-serif;
font-size: 18px;
cursor: pointer;
}
evaltest.blade.php
<html>
<head>
<title>Popup form </title>
<meta name="robots" content="noindex, nofollow">
<link href="{{ asset('css/elements.css') }}" rel="stylesheet">
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-43981329-1']);
_gaq.push(['_trackPageview']);
(function () {
var ga = document.createElement('script');
ga.type = 'text/javascript';
ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(ga, s);
})();
</script>
</head>
<!-- body starts here -->
<body id ="bdy" style="overflow:hidden;">
<div id="abc">
<!-- Popup div starts here -->
<div id="popupContact">
<!-- contact us form -->
<form class="form-horizontal" method="post" action="{{ url('/evaltest/'.$data0->id) }}">
{{ csrf_field() }}
<img id ="close" src="{{ URL::to('/image') }}/3.png" onclick ="div_hide()">
<input type="hidden" name="user_id" value="{{$data0->id}}">
<div class="form-group">
<label class="col-md-2"><b>Recommendation:</b></label>
<div class="col-md-6">
<input type="radio" id ="recommendation" name="recommendation" value="Yes"> Yes<br>
<input type="radio" id ="recommendation" name="recommendation" value="No"> No<br>
</div>
</div>
<div class="form-group">
<div class="col-md-6-offset-2">
<input id= "submit" type="submit" href="javascript: check_empty()" class="btn btn-primary" value="Save">
</div>
</div>
</form>
</div>
<!-- Popup Div Ends Here -->
// #include('test')
//it will show all data if I were to put here but I don't want to put it together with the popup form
</div>
<!-- Display Popup Button -->
//this will show a few info but no button
#include('test')
<h1>Click Button to Evaluate</h1>
<button id="popup" onclick="div_show()">Popup</button>
<script src="{{ asset('/js/my_js.js') }}"></script>
//this will show even lesser info but button is shown
//#include('test')
</body>
</html>
test.blade.php (there are more information inside but I only put some as an example of how I got the information)
<div class="container">
#foreach ($data as $object)
<b>Name: </b>{{ $object->Name }}<br><br>
<b>Alias: </b>{{ $object->Alias }}<br><br>
<b>Email: </b>{{$object->Email}}<br><br>
#endforeach
</div>
I have tried removing some of the things inside the css but nothing happen, I even try removing those with the position: fixed and also added .container but it still doesn't work.
myjs.js
// function to display popup
function div_show() {
document.getElementById('abc').style.display = "block";
}
// function to hide popup
function div_hide(){
document.getElementById('abc').style.display = "none";
}
I have figured it out how to show my data is that I have to remove the style="overflow:hidden;" part so that it will work

Problems with CSS and Chrome

My client looks great in Firefox but looks a little funky in Chrome :(
Here's some of my html code.. from the Inventory layout
<div class="clientinventory">
<div class="objtitle">
<p>Ore Inventory</p>
</div>
<div class="invitemvalue">10</div>
<div class="invitemtxtholder">Copper</div>
<div class="invitemvalue">0</div>
<div class="invitemtxtholder">Iron</div>
<div class="invitemvalue">0</div>
<div class="invitemtxtholder">Gold</div>
<div class="invitemvalue">0</div>
<div class="invitemtxtholder">Platnium</div>
</div>
Here's some of my css code.. from the Inventory layout
.invitemtxtholder {
margin-top: 5px;
margin-right: 5px;
margin-left: 5px;
background-color: #543C25;
border: 1px solid #000;
color: #FFF;
width: 60px;
text-align: center;
float: left;
clear: left;
}
.invitemvalue {
clear: right;
float: right;
font-style: italic;
color: #000;
margin-top: 5px;
margin-right: 5px;
margin-bottom: 5px;
margin-left: 0px;
width: 65px;
}
NOTE: I'm not allowed to post pictures apparently lol so heres the link
http://www.ultimate-miner.com/UM2/Client.php
I can see a difference.
The Submit button jumps down in firefox but stays inline in chrome.
Add some width with css to the submit button and that will be fixed :)

HTML Page Keeps Repeating After Form Submission

I have a PHP page that contained the following HTML elements.
<div id="templatemo_banner" onClick="parent.location='../index.php'">
<div id="logo"></div>
</div>
<div id="templatemo_menu_search">
<div id="templatemo_menu">
<?php include("../template/menu.php"); ?>
</div> <!-- end of menu -->
<div id="search_section">
<form action="#" method="get">
<input type="text" value="Enter keyword here..." name="q" size="10" id="searchfield" title="searchfield" onfocus="clearText(this)" onblur="clearText(this)" />
<input type="submit" name="Search" value="Search" alt="Search" id="searchbutton" title="Search" />
</form>
</div>
<div class="cleaner"></div>
</div>
In the respective CSS file:
#templatemo_banner {
width: 960px;
height: 288px;
margin: 0 auto;
background: url(images/templatemo_banner_bg.jpg) no-repeat;
border-bottom: 5px solid #cfd389;
}
#templatemo_banner #logo {
float: left;
margin: 100px 0 0 80px;
width: 673px;
height: 128px;
background: url(images/templatemo_logo.jpg) no-repeat;
}
#templatemo_menu_search {
clear: both;
width: 960px;
height: 50px;
background: url(images/templatemo_menu_bg.jpg) no-repeat;
}
#templatemo_menu {
float: left;
width: 650px;
height: 50px;
}
#templatemo_menu ul {
margin: 0px;
padding: 0px;
list-style: none;
}
#templatemo_menu ul li {
display: inline;
}
#templatemo_menu ul li a {
float: left;
display: block;
padding: 0 30px;
height: 35px;
padding-top: 18px;
text-align: center;
font-size: 12px;
text-align: center;
text-decoration: none;
color: #333333;
font-weight: bold;
outline: none;
}
#templatemo_menu li a:hover, #templatemo_menu li .current {
color: #ffffff;
background: url(images/templatemo_menu_hover.jpg) no-repeat;
}
I face this problem where the aforementioned html elements repeated itself once after I perform the form submission. You can picture it as if after I have my banner and menu there is an extra banner and menu below the original set. Anyway the extra elements disappear after I refresh the page.
I will appreciate any advise. I run this code in XAMPP 1.7.7 using Google Chrome as my browser.
Remove the hash in the action...
<form action="" method="get">

Categories