We have talked about making uppercase the first letters of words, sentences and lines in ASP before. Now, we will make the same application in JavaScript.
Let’s look at the UppercaseTheFirstLetter() function.
Function 1.0: UpperFunction.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
| function UppercaseTheFirstLetter(string,option){
var splitby,parts,i,uppercased;
if(option==0){splitby=" ";}
else if(option==1){splitby=".";}
else if(option==2){splitby="<br />";}
string=string.replace(/^\s+/, '').replace(/\s+$/, '');
//we removed unnecessary spaces at the beginning and ending of string.
parts = string.split(splitby);
for(i=0;i<parts .length;i++){
parts[i]=parts[i].replace(/^\s+/, '').replace(/\s+$/, '');
if(parts[i].length>0){
uppercased=parts[i].slice(0,1).toUpperCase()+parts[i].slice(1,parts[i].length);
if(i>0)output+=splitby+uppercased; else output=uppercased;
}
}
return output;
} |
This function is an avoid function that makes the first letters of all separated words, sentences or lines uppercased, then Click to Read Complete Article »
We need to know how to use properties and methods of Navigator object in JavaScript to make powerful applications. Navigator object gives us to get browser information of client. There is a list of all properties and methods in Javascript.
I. All Common Navigator Properties in JavaScript
|
Property
|
Description
|
|
appCodeName :
|
The code name of the browser (ie: Mozilla)
|
|
appName :
|
The name of the browser (ie: Netscape)
|
|
appVersion :
|
The version information of the browser (ie: 5.0 (Windows; en))
|
|
mimeTypes :
|
Returns array of all MIME types supported by the client
|
|
platform :
|
Returns the platform of visitor’s computer (ie: Win32)
|
|
plugins :
|
Returns array of all plug-ins which is installed on visitor’s computer
|
|
userAgent :
|
Returns the user-agent header (ie: Mozilla/5.0 (Windows; U; Windows NT 6.0; tr; rv:1.9.1.3) Gecko/20090824 Firefox/3.5.3 (.NET CLR 3.5.30729))
|
|
onLine :
|
Returns bolean value of browser’s online status (ie: true)
|
|
cookieEnabled :
|
Returns bolean value of browser’s cookie status (ie: false)
|
|
cookieEnabled :
|
Returns bolean value of browser’s cookie status (ie: false)
|
Click to Read Complete Article »
In this article, we will create an image slideshow including a lot of effects. We will use HTML and JAVASCRIPT. We have three files (functions.js, slideshow.html and style.css).
Application 1.0 (Creating an Image Slide Show with Javascript)
functions.js:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
| var i=1;
var r=0; //This variable contains the number of loaded images.
var address='images/';
function ChangeImage(){
var ourimage=document.getElementById("slideImg");
if (document.all && ourimage.filters){
ourimage.filters.revealTrans.Transition=Math.floor(Math.random()*23);
ourimage.filters.revealTrans.stop();
ourimage.filters.revealTrans.apply();
ourimage.filters.revealTrans.play();
}
if(i>3){ // Number of our images is 4.
i=0;
}
i++;
document.getElementById("slideImg").src = address + 'slideimage-' + i + '.jpg';
}
function SetIt(){
setTimeout("ChangeImage()",4000); // ChangeImage() function is executed each 4 seconds.
}
function startSlide() {
r++;
if(r==3){// If r reaches 3 (if third image was loaded) then show the first image and set the timer for starting the slideshow with SetIt() function.
document.getElementById("slideDiv").innerHTML='';
document.getElementById("slideDiv").innerHTML='<img id="slideImg" src="' + address + '/slideimage-1.jpg" width="370" height="200" border="0" style="filter:revealTrans(duration=1,transition=12)" onload="SetIt();" />';
}
} |
style.css: Click to Read Complete Article »
Generating random numbers is very important in Javascript like other programming languages… JavaScript adds dynamism to our html pages. For example: If you want to add a slideshow that is arranged in order at random to your page, you need to generate a random number. In this article, we will see to generate a random number by using Javascript.
Structure 1.0: This is basic statement and we don’t determine nothing like maximum or minimum limit. A float number is generated which falls between 0 and 1.
Example 1.0: Let’s get output.
1
| document.write(Math.random()); |
Probable Output of Example 1.0:
1.1) Generating a Random Number Between Two Numbers
Structure 1.1: If we want to generate Click to Read Complete Article »
There are three methods for making a loop with JavaScript. There is a list of all loop structures in JavaScript:
I. While loop
II. Do … While loop
III. For loop
I. While Loop
This statement can be very useful if you don’t have or don’t know number of repetitions because it loops the operations while specified conditions are true.
Structure 1.0 :
1 2 3 4 5
| while( conditions ){
//…
//operations
//…
} |
There is a simple code example that shows us how to use Click to Read Complete Article »
Recently Typed