How to hide part of css when input is empty? - html

I'm trying to hide the search result when the search is back to empty. Is there a way to do that?
Everything is working fine. I just don't like to see the search result of the last letter. Example if you type A and you empty the input box. The result will stay there.
Thanks to the person that know the answer.
<div id="result"></div> should be the one to be blocked.
My CSS code for the search:
.content{
width:275px;
}
#searchid
{
width:275px;
border:solid 1px #000;
padding:10px;
font-size:14px;
border-radius:5px;
-moz-border-radius:5px;
-webkit-border-radius:5px;
}
#result
{
position: absolute;
width:275px;
padding:10px;
display:none;
border-top:0px;
overflow:hidden;
border:1px #CCC solid;
background-color: white;
}
.show
{
padding:10px;
border-bottom:1px #999 dashed;
font-size:15px;
height:50px;
}
.show:hover
{
background:lightgrey;
color:#FFF;
cursor:pointer;
}
My HTML Code for the search input box:
<div class="content">
<input type="text" class="search" id="searchid" placeholder="Search"/>
<div id="result"></div>
</div>
My Search Display are like that:
<div class="show" align="left">
<span class="name">' . $rowsTitle['title'] . ' ' . $label . "<br>".
</div>
JQuery that I use to get the search information:
$(function(){
$(".search").keyup(function()
{
var searchid = $(this).val();
var dataString = 'search='+ searchid;
if(searchid!='')
{
$.ajax({
type: "GET",
url: "/sheridan/script/search.php",
data: dataString,
cache: false,
success: function(html)
{
$("#result").html(html).show();
}
});
}return false;
});
jQuery("#result").live("click",function(e){
var $clicked = $(e.target);
var $name = $clicked.find('.name').html();
var decoded = $("<div/>").html($name).text();
$('#searchid').val(decoded);
});
jQuery(document).live("click", function(e) {
var $clicked = $(e.target);
if (! $clicked.hasClass("search")){
jQuery("#result").fadeOut();
}
});
$('#searchid').click(function(){
jQuery("#result").fadeIn();
});
});
I forgot to add the JQuery function that I use to get the information out of the database.

I haven't cleared the result div as you are filling it with data when there is a letter.
$(".search").on("keyup", function(){
if($(this).val()==""){
$("#result").hide();
}
else {
$("#result").show();
}
});
Fiddle

You will have to use JavaScript to perform this action as CSS does not support any way to identify empty input fields.
I have chosen to use jQuery for this example but it could easily be achieved using no external libraries.
$('.search').on('input', function() {
$('#result').toggle( $(this).val() );
});
JSFiddle

Use JQuery
$( "#searchid" ).keypress(function() {
var search = $( "#searchid" ).val()
if(search==''){
$("#result").html();
}
});

Try following code:
$(document).ready(function(){
$("#searchid").keypress(function(){
var len = $("#searchid").val().length;
if (len <= 0)
{
//make result blank
$("#result").hide();
}
});
});
edit:
use $("#result").hide();
or
$("#result").css("display","none");

Related

Justify dynamically written text when using "white-space: pre-wrap"

I'm struggling with a detail on a project and I can't see any solution. We're getting datas writen by an Ai from a MySQL bdd and showing them as text in a fancy way http://82.223.18.239/writing.php
As you can see, the text isn't properly justified in the begining, it is when the writing process hit the bottom of the page, and I don't know how to fix this. When "white-space: pre-wrap" isn't used, everything work fine but I lose the line jump. Any help ?
Our wip code
<head>
<div id="header"></div>
<div id="body"></div>
<div id="footer"></div>
<script type = "text/javascript" src = "https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<style type="text/css">
#myTable{
width:"90%";
min-width:250px;
white-space: pre-wrap;
word-wrap:break-word;
position:absolute;
border:solid 0px;
top:200px;
left:720px;
right:720px;
bottom:50px;
font-family:"Times New Roman", Times, serif;
text-align:justify
}
#body {
padding-bottom:60px;
height:2px;
}
</style>
</head>
<body>
<div id="myTable"> <div>
<script type="text/javascript">
var skip = 0;
function get_data(index) {
$.ajax({
url : 'getData.php',
type : 'POST',
data: ({"skip":skip}),
success : function(data) {
if(data && data.trim()!='') {
skip = skip+1;
showText("#myTable", data, 0, 2);
}
else {
setTimeout(function () { get_data(skip); }, 30000);
}
},
error : function(request,error)
{
alert("Request error : "+JSON.stringify(request));
}
});
}
function showText(target, message, index, interval) {
if (index < message.length) {
$(target).append(message[index++]);
setTimeout(function () { showText(target, message, index, interval); }, interval);
}
else {
get_data(skip);
}
}
//var period = 10000; //NOTE: period is passed in milliseconds
get_data(skip);
//setInterval(page_refresh, period);
</script>
</body>

Printing what is inside a modal

I have a modal where I want to print the full contents of it. I don't want anything else printed aside what is within the modal.
Here I created the button within the modal:
This should not be printed...
<button id="btnPrint">Print (this btn should not be printed!)</button>
<hr />
<div id="printThis">
This should BE printed!
</div>
<div id="printThisToo">
This should BE printed, too!
</div>
I have some text next to the button, but this text should not show when you click the button to preview the print view.
Here I wrote some js to show what content should be printed:
document.getElementById("btnPrint").onclick = function() {
printElement(document.getElementById("printThis"));
printElement(document.getElementById("printThisToo"), true, "<hr />");
window.print();
}
function printElement(elem, append, delimiter) {
var domClone = elem.cloneNode(true);
var $printSection = document.getElementById("printSection");
if (!$printSection) {
var $printSection = document.createElement("div");
$printSection.id = "printSection";
document.body.appendChild($printSection);
}
if (append !== true) {
$printSection.innerHTML = "";
}
else if (append === true) {
if (typeof(delimiter) === "string") {
$printSection.innerHTML += delimiter;
}
else if (typeof(delimiter) === "object") {
$printSection.appendChlid(delimiter);
}
}
$printSection.appendChild(domClone);
}
Finally, I wrote some css:
#media screen {
#printSection {
display: none;
}
}
#media print {
body {
font-family: 'Open Sans', sans-serif;
font-size: 12px;
font-weight: 500;
color: #101010;
background: #f6f5fa;
visibility:hidden;
}
#printSection, #printSection {
visibility:visible;
}
#printSection {
position:absolute;
left:0;
top:0;
}
}
When I click the button in the modal, nothing happens and no errors appear in the console. Not sure what the issue is. Any help would be much appreciated.
UPDATED CODE:
(HTML)
<div>
This should not be printed...
<button ng-click="printPreview()">Print (this btn should not be printed!)</button>
</div>
<hr />
<div id="printThis">
This should BE printed!
</div>
(JS)
var app = angular.module('dmdesktop');
app.controller('PrintViewCtrl', rollUpCtrl);
rollUpCtrl.$inject = ['$scope', '$rootScope', '$http', '$uibModal','headersvc','locFiltersvc']
function rollUpCtrl($scope, $rootScope, $http, $uibModal, headersvc, locFiltersvc) {
$scope.printPreview = function() {
printElement(document.getElementById("printThis"));
}
function printElement(elem) {
alert ("printing!");
var domClone = elem.cloneNode(true);
var $printSection = document.getElementById("printSection");
if (!$printSection) {
var $printSection = document.createElement("div");
$printSection.id = "printSection";
document.body.appendChild($printSection);
}
$printSection.innerHTML = "";
$printSection.appendChild(domClone);
window.print();
}
}
(CSS)
same as before
With the updated code and window.print inside a evalAsync function allows you to print the content inside a modal
$scope.$evalAsync(function () {
window.print();
});

how to get code alignment in popup window

This code copy code functionality.when am click on copycode then it displayed code in the popup window it displayed code but align is in only one line...i have the proper alignment....enter image description here
my code displays bellow with output screens please anyone suggest me for popup alignment ..
php code
<?php
$editorDesc = '<pre class="prettyprint tryit linenums">'. htmlspecialchars(isset($outTryEditorTableInfo[$s]['editor_description']) ? $outTryEditorTableInfo[$s]['editor_description'] : '').'</pre>';
$finalResult = '<div class="ccsp-example" id="contentdiv" itemprop="articleBody" >'.$editorDesc.$tryItHereBtn.'</div><br/>'.$tryittask;
?>
css
<style>
ol li {
list-style-type: none;
counter-increment: list;
position: relative;
}
ol li:after {
content: counter(list)"\00a0 \00a0 " ;
border-right:1px solid #aeaeae;
position: absolute;
left: -2.5em;
width:4%;
text-align: right;
}
</style>
js
<script src="https://cdn.rawgit.com/google/code-prettify/master/loader/run_prettify.js?autoload=true&skin=sunburst&lang=css" defer="defer"></script>
<script type="text/javascript" language="Javascript">//<![CDATA[
$(document).ready(function () { processCodeBlocks.Initialise('#contentdiv'); });
$(function (){
$('.oauth').click(function () {
$this = $(this);
href = $this.attr('href');
var myWindow = window.open(href, 'popup',
'width=800,height=600,location=0,menubar=0,resizeable=0,scrollbars=0,toolbar=0');
myWindow.focus();
var timer = setInterval(function () {
if (myWindow.closed) {
clearInterval(timer);
// window.location.reload(); // May do a POST reload, shows a warning
window.location = window.location; // force a GET reload
}
}, 200);
return false;
});
});
</script>

How to display a progressbar in a Google Spreadsheet while a script is running

Is it possible to display a progressbar in a Google Spreadsheet while a script is running (until it is finished)?
Something like JQuery progressbar would be fine, but on which selector?
Thanks in advance for any help!
$(document).ready(function(){
$('#Mydiv').progressbar({value: false} );
})
the script you have is ok but if you want something intricate or complex, it will calculate percentages while the script is running
the CSS:
#progressbox {
border: 1px solid #0099CC;
padding: 1px;
position:relative;
width:400px;
border-radius: 3px;
margin: 10px;
display:none;
text-align:left;
}
#progressbar {
height:20px;
border-radius: 3px;
background-color: #003333;
width:1%;
}
#statustxt {
top:3px;
left:50%;
position:absolute;
display:inline-block;
color: #000000;
}
JQuery:
$(document).ready(function() {
var options = {
target: '#output',
beforeSubmit: beforeSubmit,
uploadProgress: OnProgress, //upload progress callback
success: afterSuccess,
resetForm: true
};
$('#MyUploadForm').submit(function() {
$(this).ajaxSubmit(options);
return false;
});
});
The function below captures the arguments passed by form plugin, changing the width and text of progressbar real-time.
function OnProgress(event, position, total, percentComplete)
{
//Progress bar
progressbar.width(percentComplete + '%') //update progressbar percent complete
statustxt.html(percentComplete + '%'); //update status text
if(percentComplete>50)
{
statustxt.css('color','#fff'); //change status text to white after 50%
}
}
#ref: http://www.sanwebe.com/2012/05/ajax-image-upload-with-progressbar-with-jquery-and-php
this deals with image uploads, but you can substitute it for scripts running in the background.

div content shows when display:none

I have a couple of divs that I only show after a certain action. Like a message for validation. For this one there are a couple of messages in one div, and I want them to be a couple of pixels apart. I know how to do it, but when I change the css you can see a part of the content without clicking the submit button.
With this code everything is okay, except I want the messages to be some pixels apart (padding-top: 5px or something) but when I do that you always see the padding I added, even on display: none.
My div:
<div id="fout"></div>
</div>
Style:
#fout
{
display:none;
margin-left:-75px;
display:block;
font-size:15px;
background-color:#D73033;
width:350px;
font-family:"Myriad Pro";
color:#FFFFFF;
text-align:center;
border-radius:2px;
}
Here is my jquery just in case you need it:
$(function(){
// initialisatie formulier validatie. (validate.min.js)
var validator = new FormValidator('form', [{
name: 'voornaam',
display: 'Voornaam',
rules: 'required'
}, {
name: 'achternaam',
display: 'achternaam',
rules: 'required'
},{
name: 'telefoonnummer',
display: 'telefoon',
rules: 'required|numeric'
},{
name: 'email',
display: 'email',
rules: 'required|valid_email'
}], function(errors, event) {
var berichten = document.getElementById('fout');
$("#fout").css("display","none");
$("#fout").fadeIn('slow').css;
berichten.innerHTML = '';
// als er fouten zijn:
if (errors.length > 0) {
for (var i = 0, l = errors.length; i < l; i++) {
berichten.innerHTML += errors[i].message + '<br>';
}
// als de validatie goed gegaan is:
} else {
var voornaam = $('#voornaam').val();
var achternaam = $('#achternaam').val();
var telefoonnummer = $('#telefoonnummer').val();
var email = $('#email').val();
$.post('action.php',{action: "button", voornaam:voornaam, achternaam:achternaam, telefoonnummer:telefoonnummer, email:email},function(res){
$('#result').html(res);
});
$('#insert').remove();
$("#formpje").hide('slow').css;
document.getElementById('goed').innerHTML = 'Verstuurd!';
}
// voorkom ten allertijde dat het formulier daadwerkelijk ge-submit wordt!
event.preventDefault();
});
});
you have set :
display:none;
margin-left:-75px;
display:block;
so display:block; overwrite display:none;
Remove display:block;
#fout
{
display:none; /* <-- 1st declaration */
margin-left:-75px;
display:block; /* <-- 2nd declaration which overwrites 1st declaration */
font-size:15px;
background-color:#D73033;
width:350px;
font-family:"Myriad Pro";
color:#FFFFFF;
text-align:center;
border-radius:2px;
}
EDIT
As mentioned in the comments by abhitalks
this is also a problem :
$("#fout").css("display","none"); $("#fout").fadeIn('slow').css;
EDIT 2
to give space between the lines, give :
line-height:2em; in your #fout class!!
demo here