Skip to main content

Posts

Showing posts with the label javascript

Javascript 3 dimentional matrix html board onclick empty current box

javascript 3 dimentional matrix html board onclick empty current box  Algorithm! Rules: 1. Only immediate Box can be swapped. Should not jump another box 2. Only directions allowed: Left, Right, Up, Down. 3. Should not swap diagonally.   See the Pen 3d matrix map numbers. by PV ( @moorthi07 ) on CodePen .   function hasClass(elem, className) {   return elem.className.split(" ").indexOf(className) > -1; } function addClick() {   var btn = '<button class="btn1">kkkkk</button>';   document.getElementById("container").innerHTML += btn; } // function boxbodyClick(obj) { //   /* console.log(';;;',obj.className) */ //   /* alert(obj) */ // } var arr = [3]; for (var i = 0; i < 3; i++) {   arr[i] = new Array(3); } var emti = 0; var emtj = 0; function btnClick(obj, i, j) {   if (arr[i][j] !== "-") {            if (j + 1 == emtj || j == emtj || j - 1 == emtj)...

Find Longest last name in the array.

This example shows finding longest lastname / string in an array or in a JSON object. Using: - Plain javascript conditional statments - Array.Sort function https://jsfiddle.net/marsmoorthi/umgpf3cz/5/ var namesobj = [ { 'fname' : 'senthil' , 'lname' : 'velanderson' }, { 'fname' : 'mark' , 'lname' : 'andersonvelanderson' }, { 'fname' : 'Bill' , 'lname' : 'gatesvelanderson' } ] /* firstname,lastname */ var namesarr=[ [ 'senthi' , 'velanderson' ], [ 'mark' , 'anderson' ], [ 'bill' , 'gatesvelanderson' ] ]; /* using array.sort */ function fromArraySort ( namesarr ) { var sortedArr = namesarr.sort(sortfn); function sortfn ( a,b ) { if (a[ 1 ] === b[ 1 ]) { return 0 ; } else { //Sorty by desending order return (a[ 1 ].length > b[ 1 ].length) ? -1...

Angular UI Routing (angular-ui-router) problem with '-' in the state name - model is not bound in first load.

Issue: angular-ui-router confused with state names separated with '-' . Ex. Sign-up vs Sign-up-user. Though it loads the template it is not binding the model in the first load. You have to click same link again to get the form fields populated. Angular-ui- router - almost treating it as sub url path like in " sign-up.user" the URL will be-  'sign-up/user' .  FIX: Avoid same prefix separated by '-'.  Use  some thing like  'signup-user' instead of 'sign-up-user' that repeats the other route 'sign-up'. Code:   This below code will not populate the form fields first time . app.js  .state( 'sign-up', {           url: '/sign-up',         templateUrl: 'views/sign-up-options.html'       })      .state( 'sign-up-user' , {                 ...

onClick() does not work in jsfiddle or no results when run the code

Error :   On the LHS of Jsfiddle.net below the  'Frameworks and Extensions' section,  if the dropdown option is set to Onload / OnDomreadey - the below code will not show any result.. <a href="#" id="dfddis"  onclick="Alertbox();">Alert</a> function Alertbox()          {              alert('The Alert!');                   } FIX Set the option in the dropdown menu to 'No wrap -<Body> ' / 'No wrap -< head>'. Yup! otherwise your body is messed up :( Reference http://jsfiddle.net/XPLr6/3/

jsfiddle.net {"error": "Please use POST request"} on a href = ""

Error: <a href="" id="dfddis" onclick="Alertbox();">Alert</a>       function Alertbox()          {              alert('The Alert!');                   }  - This will throw  {"error": "Please use POST request"} in jsFiddle.net Fix : Jquery tries to navigate to an empty target. A '#' will keep the link target within the same page / document. Use a '#' in the href.  <a href= "#"   id="dfddis" onclick="Alertbox();">Alert</a> Reference: http://jsfiddle.net/XPLr6/3/