Showing posts with label Jquery. Show all posts
Showing posts with label Jquery. Show all posts

Tuesday, July 3, 2018

Bootstrap show/open tabs based on url hash

6:30:00 PM 0
Bootstrap tabs can be switched based on url hash. Bootstrap has provided a jQuery method to open/show tabs programmatically. As we know manual selection of tabs will display appropriate content associated with that particular tab, but to open bootstrap tabs based on url hash follow this blog post by w3schools100

How to add URL hash with a tag

To add URL hash with anchor tag. just append hash value at the end of URL. Example https://w3schools100.blogspot.com/#myCustomHash

Get URL hash using javascript

The syntax to get URL hash is window.location.hash;. By using this, we can identify which tab to be opened.

Open bootstrap tab by jQuery

To open bootstrap tab by the function provided by bootstrap javascript, use $('.nav-tabs a[href="#myCustomHash"]').tab('show'). How to open bootstrap tab by URL hash - Example

How to open bootstrap tab by URL hash - Example

var hash = window.location.hash;
if(hash != '' || hash != undefined)
$('ul.nav a[href="' + hash + '"]').tab('show');

Friday, February 17, 2017

Select2 autocomplete dynamically from server based on input

12:53:00 PM 0
Select2 is one of the best libraries to add in the sections where to need a textbox autocomplete options. Many entry level developers feel easy to do static autocomplete feature but they feel difficult to add dynamic values in select box. 
Select2 dynamic autocompete
Select2 dynamic autocompete
Here we are going to give code to get get dynamic values in the select2 selectbox based on the input given in select2 textbox. 

<link href="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.3/css/select2.min.css" rel="stylesheet"></link>
<script src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.3/js/select2.min.js"></script>
 
<script>
  $("#select_box_id").select2({
    ajax: {
      url: "server page link",
      dataType: 'json',
      delay: 250,
      data: function (params) {
        return {
          campaign_name: params.term, // search term
        };
      },
      processResults: function (data, params) {
     var values = [];              
     $.each(data, function (key, val) { 
      if(val._id != '')
      {
        values.push({
         id: val.id,
         text: val.campaign_name
        });
      } 
     }); 
     // Sample json data -> [{ id: 0, text: 'enhancement' }, { id: 1, text: 'bug' }, { id: 2, text: 'duplicate' }]
        return { 
          results: values, //appending values from server to options tag
        };
      },
      cache: true
    },
    escapeMarkup: function (markup) { return markup; }, // let our custom formatter work
    minimumInputLength: 2,
  });
</script>
If you have any doubts, feel free to share below.. We will respond as soon as possible.

Tuesday, September 20, 2016

Jquery copy to clipboard - ctrl + c event

6:59:00 PM 0
Jquery copy to clipboard. How to copy a texbox or textarea content to clipboard using jquery. Here you will get exact result for this question. By using the below code, you can perform "ctrl + c" keyboard event automatically when a user hits a button. Lets see copy to clipboard jquery example
Jquery copy to clipboard - ctrl + c event
Jquery Control + C

Jquery copy to clipboard - ctrl + c code:


<input id="input_textbox" type="text" value="w3schools100" />
<button id="copy_but">Copy to clipboard</button>
 
<script>
    var input = document.getElementById("input_textbox");
 
    $("#copy_but").click(function(event){
        event.preventDefault();
        input.select();
        document.execCommand("copy");
    });
</script>

Search keywords: 
  • How to copy textbox contents using jquery
  • Jquery copy text to clipboard
  • Copy text box contents on a button click
  • How to trigger ctrl + c event  via code

Monday, July 25, 2016

Dim the whole page and show loading image on button click

6:15:00 PM 0
How to grey out or dim the whole page and display loading image on the center of the page, when user clicks a button ?. Most of the programmers uses ajax to request data processing. Some requests may take more time and some will take less time. As they are processing using ajax method, page won't  be refreshed or default loading button in the browser too wont work. So when user clicks a button, and if the request is in progress, we have to display a loading image to notify the users that request is in progress.

show loading image on button click
Show loading image on button click

To implement this loading image feature in your project copy the codes given below and use it in appropriate places.


/* Absolute Center Spinner */
.loading {
  position: fixed;
  z-index: 999;
  height: 2em;
  width: 2em;
  overflow: show;
  margin: auto;
  top: 0;
  left: 0;
  bottom: 0;
  right: 0;
}
 
/* Transparent Overlay */
.loading:before {
  content: '';
  display: block;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0,0,0,0.2);
}
 
/* :not(:required) hides these rules from IE9 and below */
.loading:not(:required) {
  /* hide "loading..." text */
  font: 0/0 a;
  color: transparent;
  text-shadow: none;
  background-color: transparent;
  border: 0;
}
 
.loading:not(:required):after {
  content: '';
  display: block;
  font-size: 10px;
  width: 1em;
  height: 1em;
  margin-top: -0.5em;
  -webkit-animation: spinner 1500ms infinite linear;
  -moz-animation: spinner 1500ms infinite linear;
  -ms-animation: spinner 1500ms infinite linear;
  -o-animation: spinner 1500ms infinite linear;
  animation: spinner 1500ms infinite linear;
  border-radius: 0.5em;
  -webkit-box-shadow: rgba(0, 0, 0, 0.75) 1.5em 0 0 0, rgba(0, 0, 0, 0.75) 1.1em 1.1em 0 0, rgba(0, 0, 0, 0.75) 0 1.5em 0 0, rgba(0, 0, 0, 0.75) -1.1em 1.1em 0 0, rgba(0, 0, 0, 0.5) -1.5em 0 0 0, rgba(0, 0, 0, 0.5) -1.1em -1.1em 0 0, rgba(0, 0, 0, 0.75) 0 -1.5em 0 0, rgba(0, 0, 0, 0.75) 1.1em -1.1em 0 0;
  box-shadow: rgba(0, 0, 0, 0.75) 1.5em 0 0 0, rgba(0, 0, 0, 0.75) 1.1em 1.1em 0 0, rgba(0, 0, 0, 0.75) 0 1.5em 0 0, rgba(0, 0, 0, 0.75) -1.1em 1.1em 0 0, rgba(0, 0, 0, 0.75) -1.5em 0 0 0, rgba(0, 0, 0, 0.75) -1.1em -1.1em 0 0, rgba(0, 0, 0, 0.75) 0 -1.5em 0 0, rgba(0, 0, 0, 0.75) 1.1em -1.1em 0 0;
}
 
/* Animation */
 
@-webkit-keyframes spinner {
  0% {
    -webkit-transform: rotate(0deg);
    -moz-transform: rotate(0deg);
    -ms-transform: rotate(0deg);
    -o-transform: rotate(0deg);
    transform: rotate(0deg);
  }
  100% {
    -webkit-transform: rotate(360deg);
    -moz-transform: rotate(360deg);
    -ms-transform: rotate(360deg);
    -o-transform: rotate(360deg);
    transform: rotate(360deg);
  }
}
@-moz-keyframes spinner {
  0% {
    -webkit-transform: rotate(0deg);
    -moz-transform: rotate(0deg);
    -ms-transform: rotate(0deg);
    -o-transform: rotate(0deg);
    transform: rotate(0deg);
  }
  100% {
    -webkit-transform: rotate(360deg);
    -moz-transform: rotate(360deg);
    -ms-transform: rotate(360deg);
    -o-transform: rotate(360deg);
    transform: rotate(360deg);
  }
}
@-o-keyframes spinner {
  0% {
    -webkit-transform: rotate(0deg);
    -moz-transform: rotate(0deg);
    -ms-transform: rotate(0deg);
    -o-transform: rotate(0deg);
    transform: rotate(0deg);
  }
  100% {
    -webkit-transform: rotate(360deg);
    -moz-transform: rotate(360deg);
    -ms-transform: rotate(360deg);
    -o-transform: rotate(360deg);
    transform: rotate(360deg);
  }
}
@keyframes spinner {
  0% {
    -webkit-transform: rotate(0deg);
    -moz-transform: rotate(0deg);
    -ms-transform: rotate(0deg);
    -o-transform: rotate(0deg);
    transform: rotate(0deg);
  }
  100% {
    -webkit-transform: rotate(360deg);
    -moz-transform: rotate(360deg);
    -ms-transform: rotate(360deg);
    -o-transform: rotate(360deg);
    transform: rotate(360deg);
  }
}

/* The Modal (background) */
.modal {
    display: none; /* Hidden by default */
    position: fixed; /* Stay in place */
    z-index: 1; /* Sit on top */
    padding-top: 100px; /* Location of the box */
    left: 0;
    top: 0;
    width: 100%; /* Full width */
    height: 100%; /* Full height */
    overflow: auto; /* Enable scroll if needed */
    background-color: rgb(0,0,0); /* Fallback color */
    background-color: rgba(0,0,0,0.4); /* Black w/ opacity */
}

/* Modal Content */
.modal-content {
    background-color: #fefefe;
    margin: auto;
    padding: 20px;
    border: 1px solid #888;
    width: 80%;
}

/* The Close Button */
.close {
    color: #aaaaaa;
    float: right;
    font-size: 28px;
    font-weight: bold;
}

.close:hover,
.close:focus {
    color: #000;
    text-decoration: none;
    cursor: pointer;
}
</style>
 
<span id="spinner"></span>
 
<script>
function spinner()
{
$("#spinner").html("<div class='loading'>Loading…</div>");
// To stop spinner, $("#spinner").html("");
}
</script>
 
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
 
<button onclick="spinner()">Test Spinner</button>

(Press F5 to stop the spinner..)

Tuesday, March 29, 2016

Textbox autocomplete using jquery - html5 datalist alternate method w3schools100

5:16:00 PM 0
Autocomplete textbox values by using HTML5 datalist method is an easy way to implement autocomplete function in textboxes. But the problem is, it wont work in safari browser and inner word search feature is not working in google chrome web browser.

So, we must need an alternative method to implement autocomplete textbox values. Here we are going to see, how to implement autocomplete in jquery. If you have basic working knowledge in jquery, you can easily get perfect output by using our sample code.

External files we required are,
  • jquery.min.js  (Jquery library)
  • jquery-ui.js  (Jquery autocomplete)
  • jquery-ui.css  (Jquery autocomplete CSS)
Complete code

<html>
<head>
<title>Jquery autocomplete textbox</title>

<link href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css" rel="stylesheet"></link>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
<script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>

<script>
$(function() {
 // SAMPLE ARRAY
 var arrLinks = [ 
   { id: 1, url: "http://w3schools100.blogspot.com", label: 'W3schools' },
   { id: 2, url: "http://studentsblog100.blogspot.com", label: 'StudentsBlog100' },
   { id: 3, url: "http://samplesite.com", label: 'Sample Site'} 
         ];
 //AUTOCOMPLETE FUNCTION    
 $("#text_box_id").autocomplete({
 source: arrLinks,
 messages: {
 noResults: '',
 results: function() {}
 }
 });
  
 /*AUTO COMPLETE - AFTER SELECT START*/
 $("#text_box_id").on("autocompleteselect", function (e, ui) {
 // e.preventDefault(); // prevent the "value" being written back in text box.
 
 var id = ui.item.id; //id,label,url etc..
 alert(id);

 });
 /*AUTO COMPLETE - AFTER SELECT END*/
});
</script>
</head>

<body>
Enter Keyword : <input id="text_box_id" type="text" />
</body>

</html>
Output
Textbox autocomplete using jquery w3schools100
Textbox autocomplete using jquery w3schools100