Showing posts with label javascript. Show all posts
Showing posts with label javascript. Show all posts

Javascript Loop particular number replace

Javascript Loop particular number replace

Hi,

Today We Discuss JavaScript how to replace particular number we create one loop that loop how to replace particular number to some string.

Javscript Loop particular number replace
JavaScript Loop particular number replace



var a = 100;
var str =[];
var ar = [];
for(var i=1;i<a;i++){
if(i.toString().indexOf('4') != -1){
   ar.push('buzz');
else {
   ar.push(i);
}
}
console.log(ar);  ////Replaced 4 number only Buzz


output

 [1, 2, 3, "buzz", 5, 6, 7, 8, 9, 10, 11, 12, 13, "buzz", 15, 16, 17, 18, 19, 20, 21, 22, 23, "buzz", 25, 26, 27, 28, 29, 30, 31, 32, 33, "buzz", 35, 36, 37, 38, 39, "buzz", "buzz", "buzz", "buzz", "buzz", "buzz", "buzz", "buzz", "buzz", "buzz", 50, 51, 52, 53, "buzz", 55, 56, 57, 58, 59, 60, 61, 62, 63, "buzz", 65, 66, 67, 68, 69, 70, 71, 72, 73, "buzz", 75, 76, 77, 78, 79, 80, 81, 82, 83, "buzz", 85, 86, 87, 88, 89, 90, 91, 92, 93, "buzz", 95, 96, 97, 98, 99]

How do you reverse a string in JavaScript?

How do you reverse a string in JavaScript?

 

string reverse print javascript
string reverse print javascript

 

Hi,

Today we discuss how to given string reverse print using javascript. blow code.

function stringprint(str){

let strpint = "";
for(let i=0;i<str.length;i++){
strpints = str[i]+ strpint;
console.log(strpints);
return strpints;



Reverse print ;

function reverseespringprint(str){
let reverstr = "";

for(let i>str.length-1;i>=0;i--){
revstr = reverstr+str[i] ;
console.log(revstr);
return revstr;
}

Stimulsoft Reports.JS is a platform for generating reports using JavaScript and HTML5. Angularjs

Stimulsoft Reports.JS is a platform for generating reports using JavaScript and HTML5.


Stimulsoft Reports.js is a platform for generating report using javascript and html5. Normally html design and report geneerating and stimulsoft is autometically report generation and connection string your db connection and wrtie query auto function generation report.


DBconnection
dbconnection
Stimulsoft Report is modify design any design easily modifed and watermark and everything is very easy.

View Report
View Report
Include Files:
 <link href="css/demo.css" rel="stylesheet">
 
 <!-- Report Viewer Office2013 style -->
 <link href="css/stimulsoft.viewer.office2013.whiteblue.css" rel="stylesheet">
 
 <!-- Report Designer Office2013 style -->
 <link href="css/stimulsoft.designer.office2013.whiteblue.css" rel="stylesheet">
 
 <!-- Stimusloft Reports.JS -->
 <script src="scripts/stimulsoft.reports.js" type="text/javascript"></script>
 <script src="scripts/stimulsoft.viewer.js" type="text/javascript"></script>
 <script src="scripts/stimulsoft.designer.js" type="text/javascript"></script>

 <!-- Reports -->
 <script src="reports/OnlineStoreSales.js" type="text/javascript"></script>
 <script src="reports/UsersAppleIpad.js" type="text/javascript"></script>
 <script src="reports/SmartphoneBestsellersInQ12015.js" type="text/javascript"></script>
 <script src="reports/SiteStatistics.js" type="text/javascript"></script>
 <script src="reports/HighlightCondition.js" type="text/javascript"></script>
 <script src="reports/Images.js" type="text/javascript"></script>
 <script src="reports/MasterDetail.js" type="text/javascript"></script>
 <script src="reports/MultiColumnList.js" type="text/javascript"></script>
 <script src="reports/SideBySideListWithContainers.js" type="text/javascript"></script>
 <script src="reports/SimpleGroup.js" type="text/javascript"></script>
 <script src="reports/SimpleList.js" type="text/javascript"></script>
 <script src="reports/ParametersSelectingCountry.js" type="text/javascript"></script>

 <!-- Demo data -->


<script>
  var viewer = null;
  var designer = null;
  
  function createViewer() {
   // Specify necessary options for the viewer
   var options = new Stimulsoft.Viewer.StiViewerOptions();
   options.height = "100%";
   options.appearance.scrollbarsMode = true;
   options.toolbar.showDesignButton = true;
   options.toolbar.printDestination = Stimulsoft.Viewer.StiPrintDestination.Direct;
   options.appearance.htmlRenderMode = Stimulsoft.Report.Export.StiHtmlExportMode.Table;

   // Create an instance of the viewer
   viewer = new Stimulsoft.Viewer.StiViewer(options, "StiViewer", false);
   
   // Add the design button event
   viewer.onDesignReport = function (e) {
    this.visible = false;
    if (designer == null) createDesigner();
    designer.visible = true;
    designer.report = e.report;
   };
   
   viewer.renderHtml("viewerContent");
  }
  
  function createDesigner() {
   var options = new Stimulsoft.Designer.StiDesignerOptions();
   options.appearance.fullScreenMode = true;
   options.appearance.htmlRenderMode = Stimulsoft.Report.Export.StiHtmlExportMode.Table;
   
   // Create an instance of the designer
   designer = new Stimulsoft.Designer.StiDesigner(options, "StiDesigner", false);
   
   // Add the exit menu item event
   designer.onExit = function (e) {
    this.visible = false;
    viewer.visible = true;
   }
   
   designer.renderHtml("designerContent");
  }
  
  function setReport(reportObject) {
   // Forcibly show process indicator
   viewer.showProcessIndicator();
   
   // Timeout need for immediate display loading report indicator
   setTimeout(function () {
    // Create a new report instance
    var report = new Stimulsoft.Report.StiReport();
    // Load reports from JSON object
    report.load(reportObject);

    // Remove all connections in report template (they are used in the first place)
    report.dictionary.databases.clear();
    // Registered JSON data specified in the report with same name
    report.regData("Demo", "Demo", Demo);
    // Assign the report to the viewer
    viewer.report = report;
   }, 50);
  }
  
  // Set report button style
  function setReportButton(button) {
   for (var reportName in reportsCollection) {
    var reportButton = document.getElementById(reportName);
    reportButton.isSelected = reportButton == button;
    reportButton.className = reportButton.isSelected ? "ReportButton Selected" : "ReportButton";
   }
  }
  
  // Load first report after the page is loaded
  function onBodyLoad() {
   createViewer();
   selectedButton = document.getElementById("SimpleList");
   onButtonClick(selectedButton, SimpleList);
  }
  
  // Demo Report button events
  // ---
  
  function onButtonClick(button, reportObject) {
   selectedButton.className = "ReportButton";
   button.className = "ReportButton Selected";
   selectedButton = button;
   setReport(reportObject);
  }
  
  function onButtonMouseOver(button) {
   if (button != selectedButton) button.className = "ReportButton Over";
  }
  
  function onButtonMouseOut(button) {
   if (button != selectedButton) button.className = "ReportButton";
  }
 </script>
Html Files
<body onload="onBodyLoad();">
 <div id="designerContent"></div>
 <table class="Main" cellpadding="0" cellspacing="4">
  <tr>
   <td width="150px">
    <table class="LeftPanel" cellpadding="0" cellspacing="0">
     <tr>
      <td height="60px">
       <img style="position: absolute; width: 150px; left: 0px; top: 5px;" src="images/StimulsoftReports.png" />
       <img style="position: absolute; width: 30px; height: 30px; left: 105px; top: 25px;" src="images/Js.png" />
      </td>
     </tr>
     <tr>
      <td height="90%">
       <div class="Buttons">
        <script type="text/javascript">
         // Report id and names for this Demo
         var reportsCollection = {
          "OnlineStoreSales": "Online Store Sales",
          "SimpleList": "Simple List",
          "HighlightCondition": "Highlight Condition",
          "Images": "Images",
          "MasterDetail": "Master-Detail",
          "UsersAppleIpad": "Users Apple Ipad",
          "SmartphoneBestsellersInQ12015": "Smartphone Bestsellers In Q1 2015",
          "MultiColumnList": "Multi-Column List",
          "SimpleGroup": "Simple Group",
          "SiteStatistics": "Site Statistics",
          "ParametersSelectingCountry": "Parameters Selecting Country"
         };
         // Render all report buttons
         for (var reportName in reportsCollection) {
          document.write(
           "<a class=\"ReportButton\" id=\"" + reportName + "\"" + 
           "onmouseover=\"onButtonMouseOver(this)\"" +
           "onmouseout=\"onButtonMouseOut(this)\"" + 
           "onclick=\"onButtonClick(this, " + reportName + ")\">" +
           "<table cellpadding=\"0\" cellspacing=\"0\">" +
           "<tr><td style=\"text-align: center; width: 100%;\"><img src=\"images/" + reportName + ".png\" /></td></tr>" +
           "<tr><td class=\"Caption\">" + reportsCollection[reportName] + "</td></tr>" +
           "</table>" +
           "</a>");
         }
        </script>
       </div>
      </td>
     </tr>
    </table>
   </td>
   <td height="100%" id="viewerContent"></td>
  </tr>
 </table>
</body>
</html>




Java For Beginners

  JAVA  FOR BEGINNERS  

 Java is a high level object oriented programming language.java developed by sun Microsystems in 1995.java runs on variety of platforms such as windows , Mac is , and various versions of UNIX.
Java For Beginners
Java For Beginners

Java Is Platform Independent

Platform independent is a program capability of moving from one computer system to another.
Java is portable.
Java is security.
Java is simple.

We will discuss about  simple java program

Class firstjava {
public  static void main( String args [])
{
System. out.println("hello  world");
}
}

this program has two main parts:

All the program enclosed in a class definition:  - here class called first java.

Body  of the program contained in a method called main(). In java applications as in c and c++
Program. main() is the first method or function in the program that is run when  the program is executed.


This continue will come in  next post.

Angularjs Image Crop

A simply way to crop image using  Angularjs



Image Croping
Angularjs Image Crop


Angularjs Image Crop

Whenever we allowing a user upload image, it's better to provide cropping option for them.  Touch support, swipe to move and drag handle to zoom image. Output as a base64 encoded data Url
Uses HTML5 Canvas to display image in a flexible context, to allow dragging and zooming.
Angularjs

Try this following code

Style.css

.cropImage {
  background: #E4E4E4;
  overflow: hidden;
  width:500px;
  height:350px;
}


View.html

<body ng-app="app" ng-controller="Ctrl">
  <div>Select an image file: <input type="file" id="fileInput" /></div>
  <div class="cropImage">
    <img-crop image="myImage" result-image="myCroppedImage"></img-crop>
  </div>
  <div>Cropped Image:</div>
  <div><img ng-src="{{myCroppedImage}}" /></div>
</body>


Controller.js

angular.module('app', ['ngImgCrop'])
  .controller('Ctrl', function($scope) {
    $scope.myImage='';
    $scope.myCroppedImage='';

    var handleFileSelect=function(evt) {
      var file=evt.currentTarget.files[0];
      var reader = new FileReader();
      reader.onload = function (evt) {
        $scope.$apply(function($scope){
          $scope.myImage=evt.target.result;
        });
      };
      reader.readAsDataURL(file);
    };
    angular.element(document.querySelector('#fileInput')).on('change',handleFileSelect);
  });



Jquery() Function


jQuery to replace one tag with another

Using jQuery, I'm trying to replace all the occurrences of:
<p>.....</p>

With

<h1>.....</h1>

Code


$('p').replaceWith(function(){
    return $("<h1/>", {html: $(this).html()});
});



Disabling Right Mouse Click

If you are to disable right click on your web browser, you can use the following piece of code:

$(document).ready(function(){
$(document).bind("contextmenu",function(e){
return false;
});
});


Detect Current Mouse Coordinates

Now, suppose you need to detect the current mouse coordinates in the web browser in use. To do this, you can write the following piece of code:


$(document).ready(function() {
$().mousemove(function(e)
{
$('# MouseCoordinates ').html("X Axis Position = " + e.pageX + " and Y Axis Position = " + e.pageY);
});
<div id=MouseCoordinates></div>
});



Set a Timer

The following piece of code can be used to set a timer using jQuery:

$(document).ready(function()
{
window.setTimeout(function()
{
// some code
}, 1000);
});

Jquery Ajax()

Jquery Ajax Perform Async., HTTP Ajax Request.


jQuery.ajax(url,[settings])
Jquery Ajax
Jquery Ajax()

Url

A string containing the URL to which the request is sent.

Jquery Ajax simple Code:


context

$.ajax({
  url: "test.html",
  context: document.body
}).done(function() {
  $( this ).addClass( "done" );
});

another example:

var jqxhr =
    $.ajax({
        url: "/test.html",
        data: {
            name : "The name",
            desc : "The description"
        }
    })
    .done  (function(data, textStatus, jqXHR)        { alert("Success: " + response) ; })
    .fail  (function(jqXHR, textStatus, errorThrown) { alert("Error")   ; })
    .always(function(jqXHROrData, textStatus, jqXHROrErrorThrown)     { alert("complete"); })
    ;


Disclaimer: Not all these snippet are written by me. Some of them are collected from other sources on Internet.



JavaScript Tricks

javascripttricks

Java script programming is client side scripting language.  If you  are doing lot of java script programming. very useful  java script function and tricks.

1.Use the map() function method to loop through an array value

var squares = [1,2,3,4].map(function (val) {
    return val * val;
});
// squares will be equal to [1, 4, 9, 16]

2.Converting JavaScript Array to Comma Separated Value (CSV)

You have a java script array of string or number value and you want to convert it to comma separated values(csv).

Example Code:

var arrayval = ['cat', 'apple', 'oranges', 'chares'];

var string = arrayval .valueOf();

//print string: cat,apple,oranges,chares

The valueOf() method will convert an array in javascript to a comma separated string.


3.Rounding number to N decimal place

var num =5.72121756

num = num.toFixed(4);  // num will be equal to 5.7212

4.Remove Array element by Index

function removeByIndex(arr, index) {
    arr.splice(index, 1);
}

test = new Array();
test[0] = 'Cat';
test[1] = 'Ball';
test[2] = 'bird';
test[3] = 'penguen';

alert("Array before removing elements: "+test);

removeByIndex(test, 2);


alert("Array after removing elements: "+test);

5.Comma operator

var a = 0;
var b = ( a++, 99 );
console.log(a);  // a will be equal to 1

console.log(b);  // b is equal to 99


6. Generate Random number from 1 to N

//random number from 1 to N
var random = Math.floor(Math.random() * N + 1);

//random number from 1 to 10
var random = Math.floor(Math.random() * 10 + 1);

//random number from 1 to 100

var random = Math.floor(Math.random() * 100 + 1);

7.Listbox Select All/Deselect All using JavaScript

function listboxSelectDeselect(listID, isSelect) {
    var listboxs = document.getElementById(listID);
    for(var count=0; count < listboxs.options.length; count++) {
            listboxs.options[count].selected = isSelect;
    }

}


8.Remove Duplicates from JavaScript Array

function removeDuplicates(arr) {
    var temp = {};
    for (var i = 0; i &lt; arr.length; i++)
        temp[arr[i]] = true;
    var r = [];
    for (var k in temp)
        r.push(k);
    return r;
}
//Usage
var fruits = ['apple', 'orange', 'peach', 'apple', 'orange'];
var uniquefruits = removeDuplicates(fruits);
//print uniquefruits ['apple', 'orange', 'peach''];

9. Encode a URL in JavaScript

var encodeurl= 
       "http://example.com/index.html?url=" + encodeURIComponent(myUrl);

10.Serialization and deserialization (working with JSON)

var person = {name :'dev', age : 15, department : {ID : 21, name : "R&D"} }; 
var stringFromPerson = JSON.stringify(person); 
/* stringFromPerson is equal to "{"name":"Sachine","age":31,"department":{"ID":21,"name":"R&D"}}"   */ 
var personFromString = JSON.parse(stringFromPerson);  
/* personFromString is equal to person object  */



Disclaimer: Not all these snippet are written by me. Some of them are collected from other sources on Internet.