Posts filed under 'Javascript'

validating textarea using javascript/dhtml

So many times we need to validate textarea to limit users from entering more charachters

Here is the code which is tested  in IE for validating textarea for 255 charachters.

/*copy this code in head tag */

<script language = “Javascript”>
/**
* Author : suresh kumar
*/

maxL=255;
function taLimit(taObj) {
if (taObj.value.length==maxL) return false;
return true;
}

function taCount(taObj,Cnt) {
objCnt=createObject(Cnt);
objVal=taObj.value;
if (objVal.length>maxL) objVal=objVal.substring(0,maxL);
if (objCnt) objCnt.innerText=maxL-objVal.length;
return true;
}
function createObject(objId) {
if (document.getElementById) return document.getElementById(objId);
else if (document.layers) return eval(”document.” + objId);
else if (document.all) return eval(”document.all.” + objId);
else return eval(”document.” + objId);
}
</script>

/*copy this in body */

<font> Maximum Number of characters for this text box is 255.<br>
<textarea onKeyPress=”return taLimit(this)” onKeyUp=”return taCount(this,’myCounter’)” name=”Description” rows=7 wrap=”physical” cols=40>
</textarea>
<br><br>
You have <B><SPAN id=myCounter>255</SPAN></B> characters remaining
for your description…</font>


2 comments March 4, 2008

Applying background to Iframe [IE / Firefox /Safari / Opera

<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
<html xmlns=”http://www.w3.org/1999/xhtml”>
<head>

<style>
#subscribe{
background:#ff0000;

}
</style>
<SCRIPT LANGUAGE=”JavaScript”>
function change_background() {
var iframeDoc;
if (window.frames && window.frames.subscribe && (iframeDoc = window.frames.subscribe.document)) {
// now use iframeDoc here
iframeDoc.body.style.backgroundColor=’red’;
//alert(iframeDoc.body.style.backgroundColor);
}

}
</SCRIPT>
<meta http-equiv=”Content-Type” content=”text/html; charset=iso-8859-1″ />
<title>Untitled Document</title>
</head>

<body onLoad=”change_background();”>
<iframe src=”test1.html” id=”subscribe” name=”subscribe” scrolling=”no” frameborder=”0″></iframe>
</body>

</html>


1 comment August 2, 2007

Arrays / Populating arrays / Sorting in Javascript

<body>
<script language=”javascript”>
myarray=new Array(2);               //A array intialized of size 2
myarray[1]=”suresh”;
myarray[2]=”ganesh”;
for(i=1; i<3; i++)                 //loop goes here
document.write(myarray[i]+”<br>”);
document.write(myarray.sort());         //sorting array elements
</script>
</body>


Add comment August 1, 2007

Formating / multi formating strings in javascript

<body>

<script language=”JavaScript”>

<!– formating goes here

var myVariable = suresh Theundisputed;

document.write(myVariable.big() + “<br>”);

document.write(myVariable.blink() + “<br>”);

document.write(myVariable.bold() + “<br>”);

document.write(myVariable.fixed() +”<br>”);

document.write(myVariable.fontcolor(red) + “<br>”);

document.write(myVariable.fontsize(12pt) + “<br>”);

</script>

Multi Formatting

<script language=”javascript”>
newvar=”suresh”
bol=newvar.bold().toLowerCase().fontcolor(”red”).italics(); //multiformatting
document.write(bol);

</body>


Add comment August 1, 2007

Search & Replace in javascript

<body>
<script language=”javascript”>
myvar=”test page”;                     //define a variable
sear=myvar.search(”page”);       //sear is a variable which holds result of search
if(sear==5)                                       // out put will be number
{
document.write(sear);
document.write(”<br>”);
oldvar=”hello there”;
newvar=oldvar.replace(”there”,”suresh”);       //replacing there by suresh
document.write(newvar);                      //output will be “hello suresh”
}
</body>


Add comment August 1, 2007

Window.open in js when popup is blocked

Hey u guys might be wondering what if js is blocked in a web-browser Use below code to open a new window using javascript when popup is blocked or js is degraded or js is blocked.

/* html code goes here */

<div id=”link”>
<a href=”popup.html” onclick=”fnNewWin(); return false;”>link to popup</a>
</div>

/* js for popup*/

function fnNewWin(){
window.open(’popup.html’,”,’scrollbars=no’,'resizable=no’,'addressbar=no’ );
}


Add comment July 31, 2007

Loading an Image Using JavaScript

JavaScript is a two-step process:

1. Create an Image object and assign it to a variable:

var myImage = new Image;

2. Assign a source image URL to the src attribute of the object:

myImage.src = “image URL goes here”;

The following task illustrates the programmatic loading of an image by loading

an image in this way and then providing links to display the height and width of

1. Create a script block with opening and closing script tags.

2. In the script, create a new Image object named myImage:

myImage = new Image;

3. Load the image by assigning its URL to the src attribute of

myImage:

myImage.src = image1.jpg;

4. In the body of the page’s HTML, include a link for displaying the

width and add an onClick event handler to the a tag; this eventhandler will use the

window.alert method to display the image’s

width in a dialog box. The image’s width is obtained by referring to

document.myImage.width:

<a href=#” onClick=window.alert(document.myImage.width)Æ

”>Width</a><br>

5. Include a link for displaying the height, and add an onClick event

handler to the a tag; this event handler will use the window.alert

method to display the image’s height in a dialog box. The image’s

width is obtained by referring to document.myImage.height. The

final page should look like the following:

<script language=JavaScript”>

myImage = new Image;

myImage.src = Tellers1.jpg;

</script>

<body>

<a href=#” onClick=window.alert(myImage.width)

”>Width</a><br>

<a href=#” onClick=window.alert(myImage.height)

”>Height</a>

</body>


1 comment June 25, 2007

Introduction

JavaScript is the scripting language of the Web!

JavaScript is used in millions of Web pages to improve the design, validate forms, detect browsers, create cookies, and much more.

JavaScript is the most popular scripting language on the internet.

JavaScript is easy to learn! You will enjoy it!


Add comment April 10, 2007


Spam Blocked

Flickr Photos

THE-GROUP-YOU-CANNOT-GET-INTO-ANYMORE

.pouting.

L'informarsi, prima di tutto

More Photos

Categories

Links

Calendar

August 2008
M T W T F S S
« Jun    
 123
45678910
11121314151617
18192021222324
25262728293031

Recent Posts

Recent Comments

Sachin Gajraj on Top 50 Govt Engineering C…
Sachin Gajraj on Top 50 Govt Engineering C…
KUSHAGRA on Top 50 Govt Engineering C…
Siber on 5 useful PHP functions for MyS…
Daniel Tome on Applying background to Iframe …

Pages

Top Clicks

Top Posts

Blog Stats