Showing posts with the label javascript

Copy a text of div by button click by javascript

Your html code  <input type="button" id="copyme" value="COPY THE DIV"> <div id="mypolicy">THIS IS WHAT I WANT TO COPY</div> js script $('#copyme').on('click', function(){     id =     var range = document.createRange();     range.selectNode(document.getElementById(id));     window.getSelection().removeAllRanges();   // clear current selection     window.getSelection().addRange(range);   // to select text     document.execCommand("copy");   });

How to use switch case in angular view

      <div ng-switch =" varible_name ">           <div ng-switch-when ="value1"><p>{{ value1}}</p></div>           <div ng-switch-when ="value2"><p>{{ value2 }}</p></div>           <div ng-switch-when ="value3"><p>{{ value3 }}</p></div>           <div ng-switch-when ="value4"><p>{{ value4}}</p></div>           <div ng-switch-default >...</div>       </div>

Get Height and Width of Image when upload

<script type="text/javascript">  var _URL = window.URL || window.webkitURL;  $('#structure_product_image').on('change', function() { //pass here file field id    var image, file;    if ((file = this.files[0])) {      image = new Image();      image.onload = function() {        $("#error_message").text("");        if (this.width <= 700) {          $("#error_message").text("Width should be greater than 700 pixel!") //id where you want to display text        }        else if (this.height <= 600){          $("#error_message").text("Height should be greater than 600 pixel!")        }        else if (this.height >= this.width){          $("#error_message").text("Height should not be greater than Width")        }        if($("#error_message").text() == ""){          $("#save_product").prop("disabled" , false)      

Download pdf by ajax or javascript or angular js

Click on button for generate pdf  $("#print_selected_label").on("click", function(){    data = []    $("input:checkbox.print_label:checked").each(function(){      data.push($(this).attr("id"));    });   //getting all information of checked checkbox    if(data.length > 0){    // if data is not null       In angular js controller         // var redirect_new = "/admin/v2/orders/print_multiple_label.pdf?" + jQuery.param(data);        // var pdf =, 'Map PDF', '');      By Creating a link by javascript       // var mydiv = document.getElementById("download_pdf");      // var aTag = document.createElement('a');      // var link = " admin/v2/orders/print_multiple_label.pdf?id="+data ;      // aTag.setAttribute('href',link);      // aTag.innerHTML = "link text";      // mydiv.appendChild(aTag);      //; By making http request    

How to customise active admin page on keypress

How to customise active admin page on keypress First make new route for getting filtered data: get '/admin/gyms/search_user', :to => 'admin/gyms#search_user', as: :search_gym_user In your controller create new method def search_user      @user =  User.where("name = ? AND role = ?", params[:name], "none") if params[:name].present?      respond_to do |format|        format.json  { render :json => @user }      end    end Render partial and add a id to to table panel "Gym Users:", :id => "foo-panel" do      # renders app/views/admin/posts/_search_users.html.erb       render 'search_users', { users: gym.users }      table_for gym.users, id: "search_gym_user" do        # binding.pry        # filter :"name" , :as => :select, :collection => gym.users.pluck(:name)        column "Joined" do |user|          distance_of_time_in_words(user.created_at,    

flash message in javascript

In html file - <button class="click-here">Click here to show message</button> <div id="status-area"></div> In javascript file -  (function($) {     $.fn.flash_message = function(options) {              options = $.extend({         text: 'Done',         time: 1000,         how: 'before',         class_name: ''       }, options);              return $(this).each(function() {         if( $(this).parent().find('.flash_message').get(0) )           return;                  var message = $('<span />', {           'class': 'flash_message ' + options.class_name,           text: options.text         }).hide().fadeIn('fast');                  $(this)[](message);                  message.delay(options.time).fadeOut('normal', function() {           $(this).remove();         });                });     }; })(jQuery); Add some css-

Show Escape or Enter and tab in column or row in Rails

Show Escape or Enter and tab in column or row in Rails @users.each do |user|      raw(user.address.gsub(/\n/, '<br>'))   end //assuming you have \n or enter in your record and if you have another Special character then replace that character wiht respective html tag

Searching on Select Box and Check Box || List

Searching on Select Box and Check Box Searching on List <input type="text" id="myInput" onkeyup="filterFunction()" placeholder="Search.." > <ul id="myulli">   <li><a href="#">abc</a></li>   <li><a href="#">xyz</a></li>  <li><a href="#">demo</a></li> <li><a href="#">testing</a></li> </ul> <script> function filterFunction(){    var input, filter, ul, li, a, i;    input = document.getElementById("myInput");    filter = input.value.toUpperCase();    div = document.getElementById("myulli");    a = div.getElementsByTagName("li");    console.log(a);    for (i = 0; i < a.length; i++) {        if (a[i].innerHTML.toUpperCase().indexOf(filter) > -1) {            a[i].style.display = "";        }

Make admin panel with Active admin rails || active_admin rails

Make admin panel with Active admin rails || active_admin rails  Open Terminal and copy and paste this Command rails new admin_example // creating new rails application go inside the project cd admin_example run bundle install bundle install open your gem file and add this new gem's gem 'activeadmin' / / for active admin panel gem 'inherited_resources' //  making your controllers inherit all restful actions gem 'devise' // for user authentication  run bundle install again bundle install install active admin rails g active_admin:install / /install active admin to your project migrate database rake db:migrate check your seed file and run rake db:seed create user file and model rails g User name email  create post file and model rails g Post title body:text published_at:datetime user:references Now Migrate DataBase rake db:migrate start rails server rails s Hit url localhost:3000/admin/login Enter login details you can find login

Features of Sql * Plus

Features of Sql * Plus At a time only one query is allowed to execute Sql queries are not case sensitive Each query is terminated with ; ( semi colon ) SQL commands are ANSI standard ( American National standard institute )

What is sql definition(Structured query language). Sql Tutorial -2

Structured query language It is a collection of pre defined commands and constructs with syntactical rules. 1. Sql is a client tool to interact with ORACLE DB /any DB 2. Sql is to be installed in to the system whenever we have installed the db software. 3. Client [Technical] requests should be submitted in the form of "Queries". 4. Queries are executed by SQL STMT EXECUTOR ( Oracle Db Engine ) 5. Queries are executed against database and output will be displayed on the Sql * plus window.

What is WebPack || WebPack React app by webpack || babel loader || babel core || babel

Webpack is a tool that puts all your assets including images,javascript ,fonts and css in a dependency graph entry point: is the file webpack looks for to start building your Javascript bundle webpack’s main strength is code splitting. It introduce a production mode and development mode. As ,, Syntax of  ReactJS is based on ES6. old browsers doesn’t understand ES6. So , to run JS we need something which transform our ES6 code to browser understand language , the same thing is done by babel-loader. Babel-loader is a webpack loader for transpiling ES6 and above , down to ES5. For this, you need three things - babel-core, babel-loader, babel-preset-env   Commands- 1. npm init: This cmd create a package.json file . 2.npm i webpack --save-dev: This cmd generate dependencies for webpack in package.json file. Like "devDependencies": {    "webpack": "^4.16.2"  } 3. npm i webpack-cli --save-dev : This cmd is

Create react app by yarn-server || yarn Server || React App

first of all install Yarn from here click on get started and install yarn server Create a directory mkdir <your_directory_name> Run command yarn init (press enter and use all defaults) by this command package.json file will be created in root directory for creating Dependency we run this command yarn add babel-cli babel-preset-react --dev yarn add babel-cli babel-preset-env --dev yarn global add babel-cli babel-preset-env babel-preset-react ( Installed "babel-cli@6.26.0" with binaries:  - babel-doctor  - babel  - babel-node  - babel-external-helpers ) Now again make a directory inside root directory mkdir public (you can take name as you want) mkdir src (you can take name what ever you want you want) inside public folder create two new file index.html index.js inside src folder create one new file  main.js ( this is file where react app execution is start. you can take name what ever you want). Add this code into your i

How can I create thread array?

int [] testscore = new int[4];  //create an array of size 4. similarly we create thread array, Thread threads = new Thread[5]; // no thread objects created!   one   Thread array created Remember that, we are not creating a thread instance ,but rather a single Thread array object.

my input a=12, but how do I print this in 3 digits?

There are many ways to do this. I am using the simplest way to print two digit number in three digit number. import java . util . Scanner ; class Digit { public static void main ( String [] args ) { Scanner sc = new Scanner ( System . in ); System . out . println ( "please enter any two digit number:" ); int n = sc . nextInt (); int k = 0 ; if ( n > 9 && n < 100 ) { k = n * 10 ; } else { System . out . println ( "please enter any two digit number:" ); } System . out . println ( "you entered " + n + " and three digit output of this number is " + k ); } Read More