Skip to main content

Posts

Showing posts with the label Javascript

How to replace plain URLs with links

Here we will explain how to replace Urls with links from string Using PHP $string ='Rajiv Uttamchandani is an astrophysicist, human rights activist, and entrepreneur. Academy, a nonprofit organization dedicated to providing a robust technology-centered education program for refugee and displaced youth around the world.  CNN Interview - https://www.youtube.com/watch?v=EtTwGke6Jtg   CNN Interview - https://www.youtube.com/watch?v=g7pRTAppsCc&feature=youtu.be'; $string = preg_replace('@(https?://([-\w\.]+)+(:\d+)?(/([\w/_\.%-=#]*(\?\S+)?)?)?)@', '<a href="$1">$1</a>', $string); Using Javascript <script> function linkify(inputText) {     var replacedText, replacePattern1, replacePattern2, replacePattern3;     //URLs starting with http://, https://, or ftp://     replacePattern1 = /(\b(https?|ftp):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/gim;     replacedText = inputT...

How to change integer value in number format jQuery

Here are simple way you can change integer value in number format on key up using jQuery Html Code: <input type="text" name="amount" class="required" value=""> jQuery Code: <script> jQuery.noConflict(); jQuery(document).ready( function($){  $(document).on('keyup', 'input.required', function(event){ if($(this).hasClass('field-error')){ $(this).css('border-color', '#83A4C5'); $(this).removeClass('field-error'); }    var selection = window.getSelection().toString(); if ( selection !== '' ) { return; }            // When the arrow keys are pressed, abort it. if ( $.inArray( event.keyCode, [38,40,37,39] ) !== -1 ) { return; }       var $this = $( this );            // Get the value. var input = $this.val();             var input = input.replace(/[\D\s\._\-]+/g, ""); input = input ? pa...

How to Implement CRUD in Node js With MySQL

How to Implement CRUD in Node.js With MySQL In this post, we are going to create a simple CRUD application in Node.js with MySQL as the database. We are using EJS as the template engine. Before get started with this tutorial: You need to have Node installed. Read my previous post for Node.js installation. Step 1: Create index.js as main file and package.json file package.json { "name": "curdnode", "version": "1.0.0", "description": "Create simple curd example in nodejs", "main": "index.js", "scripts": { "start": "node index.js", "test": "echo \"Error: no test specified\" && exit 1" }, "author": "techsudhir", "license": "ISC" } index.js console.log('Welcome You'); Now open up your command line and run : npm start Output: Welcome You Stop the c...

Simple JavaScript Object and Class Examples

In JavaScript, most things are objects. An object is a collection of related data and/or functionality Namespace: Everything you create in JavaScript is by default global. In JavaScript namespace is Global object . How to create a namespace in JavaScript? Create one global object, and all variables, methods, and functions become properties of that object. Example:  // global namespace var MYAPP = MYAPP || {}; Explaination: Here we first checked whether MYAPP is already defined.If yes, then use the existing MYAPP global object, otherwise create an empty object called MYAPP How to create sub namespaces? // sub namespace MYAPP.event = {}; Class JavaScript is a prototype-based language and contains no class statement.JavaScript classes create simple objects and deal with inheritance. Example: var Person = function () {}; Explaination: Here we define a new class called Person with an empty constructor. Use the class keyword class Calculation {}; A class expr...

How to learn NodeJs in 5 steps

NodeJs Entry level Tutorial Node.js is an open-source, cross-platform JavaScript runtime environment for developing a diverse variety of tools and applications. It is a server-side platform built on Google Chrome's JavaScript Engine Follow Basic steps to run your first example Step1: Download Nodejs and install it. Step2: After installation Check NodeJs working or not a) Open Windows Command Prompt b) Execute the Command node -v. It print a version number Example: C:\Users\Sudhir>node -v Output: v6.9.2 c) Execute the Command npm -v . It print NPM’s version number Example: C:\Users\Sudhir>npm -v Output: 3.10.9 Step3: Type npm init and press enter Step4: It will ask for file name, version and description etc Step5: It will create a package.json file { "name": "nodetest", "version": "1.0.0", "description": "Hello test", "main": "index.js", "scripts": { ...

JSON and JSONP in Javascripit

JSON and JSONP in Javascripit JSON is a subset of the object literal notation of JavaScript. JSON in JavaScript Example: var myJSONObject = {"Address": [ {"city": "Azamgarh", "state": "Uttar Pradesh", "country": "INDIA"}, {"city": "Lucknow", "state": "Delhi", "country": "USA"}, {"city": "Noida", "state": "Goa", "country": "UK"} ] }; Code Explaination: Here bindings is an object. It contains array of 3 object. Members can be retrieved using dot or subscript operators. Example : myJSONObject.bindings[0].method JSON Objects JSON objects are written inside curly braces Example : var name = {"firstName":"John", "lastName":"Doe"} JSON Arrays JSON arrays are written inside square brackets. Example : var employeeList = "emplo...

Javascript Local Storage

Javascript Local Storage LocalStorage is used to stored web application data within the user's browser. LocalStorage is only store strings in the different keys How to check user's browser support? if (typeof(Storage) !== "undefined") {     // Code for localStorage/sessionStorage. } else {     // Sorry! No Web Storage support.. } How to Set Values in localStorage localStorage. setItem ('favoriteflavor','vanilla'); How to Access localStorage variable If you read out the favoriteflavor key, you will get back “vanilla”: var taste = localStorage. getItem ('favoriteflavor'); How to remove Elements from localStorage localStorage. removeItem ('favoriteflavor'); var taste = localStorage.getItem('favoriteflavor'); How to Store Array in LocalStorage localStorage is for key : value pairs, so what you'd probably want to do is JSON.stringify the array and store the string in the mycars key and then you can pul...