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 Special Characters in C#

In JavaScript you can add special characters to a text string by using the backslash sign.

Insert Special Characters
The backslash (\) is used to insert apostrophes, new lines, quotes, and other special characters into a text string.

Look at the following JavaScript code:

var txt="We are the so-called "Vikings" from the north.";

In JavaScript, a string is started and stopped with either single or double quotes. This means that the string above will be chopped to: We are the so-called

To solve this problem, you must place a backslash (\) before each double quote in "Viking". This turns each double quote into a string literal:

var txt="We are the so-called \"Vikings\" from the north.";

Code Outputs
\' --> single quote
\" --> double quote
\& --> ampersand
\\ --> backslash
\n --> new line
\r --> carriage return
\t --> tab
\b --> backspace
\f --> form feed

Example 2

_List.ListRow.AddColumn("" + GetStatus(_COSTLINE.GetSTATUS()) + " ", "Left", false, "7%");

How to get ID of element that triggered an event with class name

function overfade(evnt)
var obj = Event.element(evnt);

Return characters only on key press event in JavaScript

How can I return only character to be entered A-Z a-z on key press event . Restrict numbers and other key using javascript

< script>
function char(e) {
e = (e)?e:window.event;
key = String.fromCharCode(e.keyCode);
if (key.match(/[a-zA-Z]/)) return true;
return false

< /script>
< input onkeydown="return char(event)">

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)


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.

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.

Tab Stop on Disabled Text Boxes

One option is to add the onkeyup attribute to the input element for the quantity that will check if the disabled text box qualifies to be enabled and if yes enables it. The code snippet below has a successfully tested example that is simple.The onkeyup event of the quantity input element is called immediately after the user entered something into the quantity field, we then check if the criteria is met and if yes enable the initially disabled text box so that by the time the user tabs to it, it is already enabled and the tab works.

input type="text" id="txtQuantity" onkeyup="if(this.value != '') { document.getElementById('txtSecondBox').disabled = false; }" />

input type="text" id="txtSecondBox" disabled="disabled" />

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.

Pattern matching in Javascript

var pattern1 = /^[789]{1}[\d]{2}[AaBbCcDd]{1}$/;
var pattern2 = /^[3456]{1}[1234]{1}[\d]{2}[AaBbCcDd]{1}$/;
var pattern3 = /^[54]{1}[12345]{1}[\d]{2}[YyZz]{1}$/;

if (!obj.match(pattern1) || !obj.match(pattern2) || !obj.match(pattern3)) {
alert("Doesn't match!");
return false;

JavaScript : IsDate function

function isDate(dtStr){
var daysInMonth = DaysArray(12)
var pos1=dtStr.indexOf(dtCh)
var pos2=dtStr.indexOf(dtCh,pos1+1)
var strMonth=dtStr.substring(0,pos1)
var strDay=dtStr.substring(pos1+1,pos2)
var strYear=dtStr.substring(pos2+1)
if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
for (var i = 1; i <= 3; i++) {
if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
if (pos1==-1 || pos2==-1){
alert("The date format should be : mm/dd/yyyy")
return false
if (strMonth.length<1 || month<1 || month>12){
alert("Please enter a valid month")
return false
if (strDay.length<1 || day<1 || day>31 || (month==2 &&
day>daysInFebruary(year)) || day > daysInMonth[month]){
alert("Please enter a valid day")
return false
if (strYear.length != 4 || year==0 || yearmaxYear){
alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear)
return false
if (dtStr.indexOf(dtCh,pos2+1)!=-1 ||
isInteger(stripCharsInBag(dtStr, dtCh))==false){
alert("Please enter a valid date")
return false
return true

Function : Currency formatting in JavaScript

This function will convert numeric value (interger or float) into the formatted currency:

function num2money(n_value) {
// validate input
if (isNaN(Number(n_value)))
return 'ERROR';

// save the sign
var b_negative = Boolean(n_value < 0);
n_value = Math.abs(n_value);

// round to 1/100 precision, add ending zeroes if needed
var s_result = String(Math.round(n_value * 1e2) % 1e2 + '00').substring(0, 2);

// separate all orders
var b_first = true;
var s_subresult;
while (n_value >= 1) {
s_subresult = (n_value >= 1e3 ? '00' : '') + Math.floor(n_value % 1e3);
s_result = s_subresult.slice(-3) + (b_first ? '.' : ',') + s_result;
b_first = false;
n_value = n_value / 1e3;
// add at least one integer digit
if (b_first)
s_result = '0.' + s_result;

// apply formatting and return
return b_negative
? '($' + s_result + ')'
: '$' + s_result;

JavaScript :Calculator


JavaScript : Formatting numbers for decimals and digits

Formatting numbers for
decimals and significant digits in JavaScript

Formatting numbers so they confirm to a specific format can be
deceivingly tricky. For example, one of the most common tasks is to format a
number for currency display- an integer followed by two decimals. You may be
tempted to use number rounding to first shift the number's decimal places (via multiplication),round it, then shift the decimal back (via division) to pound the number into your hard earned dollar, though that won't work in many cases. For example, consider the number 120. Number rounding certainly won't get you to 120.00.

To easily format numbers for a specific number of trailing
decimals or total digits (aka padding), JavaScript 1.5 introduces the below
two nifty methods:




Formats any number for "x" number of trailing
decimals. The number is rounded up, and "0"s are used after the
decimal point if needed to create the desired decimal length.


Formats any number so it is of "x" length. Also
called significant digits. A decimal point and "0"s are used if
needed to create the desired length.


The best way to see all the subtleties of toFixed() is to see it in action:

var profits=2489.8237

//returns 2489.824 (round up)

//returns 2489.82

//returns 2489.8237000 (padding)

Displaying any number in currency format can't get any easier!


To toPrecision() now:

var anumber=123.45

//returns 123.450 (padding)

//returns 123.5 (round up)

//returns 1.2e+2 (you figure it out!)

toPrecision() is useful if your number must be of a certain length.


Now, as noted, our two heros above are JavaScript 1.5 methods.
What this means is that they'll only work in IE5.5+ and NS6+. The issue of
legacy browsers not performing the desired formatting operation not
withstanding, how do you ensure that these two methods at least degrade well?
Well, by using method detection in your code. For example:

var profits=2489.8237

if (profits.toFixed)
//if browser supports toFixed() method


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.


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

Visual Studio 2017'de Devexpress 17.2.5 Toolbox görünmüyor

Visual Studio 2017 Toolbox'ı üzerinde Developer Express componentlerini göremiyorsanız aşağıdaki komutu çalıştırmak işini görecektir. (...