Java Script etiketine sahip kayıtlar gösteriliyor. Tüm kayıtları göster
Java Script etiketine sahip kayıtlar gösteriliyor. Tüm kayıtları göster

Excel GÜN360/DAYS360 benzeri Datediff360 Javascript fonksiyonu

Excel'deki GÜN360/DAYS formülü ile yapılan fonksiyonun Javascript kodu aşağıdaki fonksiyon ile kullanılabilir. (DATEDIFF360)


JavaScript Kodu:

function Datefark360( dtIlkTarih, dtSonTarih ) {
  var fark = [
               dtSonTarih.getFullYear() - dtIlkTarih.getFullYear(),
               dtSonTarih.getMonth()    - dtIlkTarih.getMonth(),
               dtSonTarih.getDate()     - dtIlkTarih.getDate(),
               dtSonTarih.getHours()    - dtIlkTarih.getHours(),
               dtSonTarih.getMinutes()  - dtIlkTarih.getMinutes(),
               dtSonTarih.getSeconds()  - dtIlkTarih.getSeconds()
             ];
  var carpan = [ 12, 31, 24, 60, 60 ];
  carpan[ 1 ] = ( new Date( dtSonTarih.getFullYear(), dtSonTarih.getMonth(), 0 ) ).getDate();

  for ( var i = fark.length - 1; i > -1; i-- ) {
    if ( fark[ i ] < 0 ) {
      if ( i > -1 ) {
        var j = i - 1;
        fark[ i ] += carpan[ j ];
        fark[ j ]--;
      } else {
        alert( 'Negatif Yıl: ' + fark[ 0 ] );
      }
    }
  }
  return fark[ 0 ] * 360 + fark[ 1 ] * 30 + fark[ 2 ];
}

ASP.NET üzerinde Butonu disable etmek

ASP.NET üzerinde Butona tıklandığında butonun disable edilmesi için aşağıdaki kod aspx dosyasına eklenir.
UseSubmitBehavior="false" OnClientClick="this.disabled=true;this.value = 'Lütfen Bekleyiniz...';"

Prevent unchecking of a checkbox in Java Script

<\input type="checkbox" onclick="if(!this.checked)this.checked=true"\>

Prevent href in Java Script




Create a for Loop in JavaScript

JavaScript, like all programming languages, supports loops or repetition, in its case with the for statement. The for statement in JavaScript comes in two flavors: one loops over values, the other over entries in an object or array.

Loop Over Values in JavaScript
1. Code the for statement, following the syntax below:
for (variable=value; condition; increment) { statement(s) }

2. Loop over a range of values by setting a variable equal to the initial value, specifying for the condition the test that the variable not exceed the maximum value, and incrementing the variable each time through the loop. In the example below, the numbers between 1 and 9 will be displayed in a series of alert boxes. (i++ means to increment the value of the variable i by 1.)
for (i=1; i<10; i++) { alert (i); }

3. Terminate processing of the loop's statements and return to the top for the next iteration, if necessary, by using the continue statement.

4. Break out of the loop, continuing with the statement following it, by coding a break statement if necessary.



Loop Over Object or Array Elements

1. Code the for statement, following the syntax below. "in" is a special JavaScript keyword used for this purpose.
for (variable in object) { statement(s) }

2. Process each element in the object or array as appropriate. The variable given in the for statement will take on the value of each array index, or object field, in turn. Example:
for (i in my_array) { alert ("Value of element " + i + " is " + my_array[i]);

3. Move to the next iteration, or break out of the loop, using the same continue and break statements described in the preceding section.

JavaScript: Copy to a Date var

1.First you start with the Date object you want to copy; let's call that "d1".
2.Create a new Date object where you want to copy the value to, say "d2":
"var d2 = new Date()".
3.Call "setTime" on the new variable and pass in the "valueOf()" of your source date: "d2.setTime(d1.valueOf())".

How to create a For Loop In JavaScript?

1- A basic While Loop.
The Basic While Loop-First of all you just need to understand the while loop in it's most basic form, so that you'll understand how the for loop works. Lets take a look at a very basic form of the while loop:
i = 0;
while(i <= end)
{...i++;

)

First of all you'll notice the "i" variable, this will most likely be declared as an int by the way, it's basically what will keep count of the number of times the computer is supposed to go through the loop. You'll also notice the i++ inside the loop, this is what makes the "i" variable go up by one after every loop. It can then stop looping once it reaches whatever you've set the "end" variable to, which will more than likely be an int as well.

2-Variables
Now we'll take a look at the for loop piece by piece. The for loop itself is really just shorthand in Java for the above while loop. it's also going to have an "i" variable, so you could go ahead and declare that. It'll also have a starting value, which was zero in the while loop above, and an end value. Just make sure the starting value is smaller than the end value, and that it will eventually reach the end value. Don't want an infinite loop do you?
int i;
int begin;
int end;
3-Start, End, And Count-
Now all you have to do is to set up the for loop:
for(i = begin; i <= end; i++)

Just remember that you can set the beginning and ending values to whatever you need them to be.

How to add a "Bookmark Us" Link to Your Website or Blog using Javascript

1.Open your blog or webpage code editor. There will typically be an option in your blog interface or web page design software. The default editing option is usually "Visual" or "WYSIWYG". Look for "edit HTML" or similar.


2.Within your code, locate the BODY tag. This will come after the HEAD tag. You will need to add the code below right after the BODY tag.


3.Save your page and upload to your server if you have your own website. If you have a blog, you will need to save and publish.

FUNCTION: isNaN (Java Script)

The isNaN function is used to determine if the argument, testvalue, is a NaN.

A NaN, which means "Not-a-Number", is classified as a primitive value by the ECMA-262 standard and indicates that the specified value is not a legal number.

The function returns true if the argument is not a number and false if the argument is a number.

The classic example of a NaN is zero divided by zero, 0/0.

Code:

document.write(isNaN("Ima String")) // true

document.write(isNaN(0/0)) // true

document.write(isNaN("348")) // false

document.write(isNaN(348)) // false

Round to a certain number of places in Java Script

For rounding decimals you can use the built-in JavaScript methods toFixed or toPrecision.

Round to a certain number of places
For rounding decimals you can use the built-in JavaScript methods toFixed or toPrecision.


var num = 10;
var result = num.toFixed(2); // result will equal 10.00

num = 930.9805;
result = num.toFixed(3); // result will equal 930.981

num = 500.2349;
result = num.toPrecision(4); // result will equal 500.2

num = 5000.2349;
result = num.toPrecision(4); // result will equal 5000

num = 555.55;
result = num.toPrecision(2); // result will equal 5.6e+2

Adding TextBox Values using Javascript in C#

The following code sample shows how to add the textbox values using javascript.

The keyup event of the textbox is used. Three textboxes is use , the functionality is to add the first and second textboxes and total in third textbox.

Step 1-The Javascript Function follows :

function KeyUpEvent()
{
var txt1 = document.getElementById("txt1");
var txt2 = document.getElementById("txt2");
var txt3 = document.getElementById("txt3");
if ((txt1.value != "") && (txt2.value != ""))
{
txt3.value = parseInt(txt1.value) + parseInt(txt2.value);
}
}

Step 2-Design





Step 3-To add attributes to the textbox at code behind use this example:

txt1.Attributes.Add("onKeyUp", "javascript:KeyUpEvent();");
txt2.Attributes.Add("onKeyUp", "javascript:KeyUpEvent();");


How to convert a float, interger value to string?

Integer (int) or float value can be converted to string by using the function or method toString().


var a = 3.22;
a.toString(); // "3.22"

var a = 5;
a.toString(); // 5

Converting a string data type to float in javascript?

To convert a value from string to float, we have to use the function or method "parseFloat() to convert a string value to float.

Example:

parseFloat("4.333"); // 4.333
parseFloat("5aaa"); // 5
parseFloat("6e2"); // 600
parseFloat("aaa"); // NaN (means "Not a Number")

BlackListIP control on Serenity platform (.NET Core)

 In the Serenity platform, if you want to block IPs that belong to people you do not want to come from outside in the .net core web project,...