Developers Archive for the 'Javascripts' Category

Javascript String Split Function

Javascript String Split Function Friday, March 16th, 2007

A string can be splitted in javascript by using the split() function. The split function takes the delimiter as an arguement. Whenever it sees the delimiter the string is splitted and stored in the array.

sample code:
<script type=”text/javascript”>
var myString = “Javascript string split function”;

var mySplitString = myString.split(” “);

for(i = 0; i < mySplitString.length; i++)
{
 document.write(”<br /> Element ” + i + ” = ” + mySplitString[i]);
}
</script>

In the above example the delimiter used is the space character ” “. Thus the split function splits the given string whenever it finds the space character and stores the result in the array. The result can be viewed by looping through the elements of the array with its length.

Result:
Element 0 = Javascript
Element 1 = string
Element 2 = split
Element 3 = function

Disabling form double-submits

Disabling form double-submits Friday, March 16th, 2007

We can disable double submission by using the following javascript code. We can just add the following code to our submit button:

onclick=”this.disabled=true,this.form.submit();”

The javascript is executed the first time someone clicks the submit button. The first bit of code ‘this.disabled=true’ disables the button so it can’t be clicked again. The second bit of code ‘this.form.submit()’ then submits the form results (the form won’t work at all without this code).

<form>
<input type=”submit” value=”Send” onclick=”this.disabled=true,this.form.submit();”>
</form>

Make This Site as Home Page Button using Java script

Make This Site as Home Page Button using Java script Thursday, March 15th, 2007

We can provide an option for visitors to make our site as Home Page.

This JavaScript code will enable to place a button on our site that, when clicked on, will make our web site visitors home page.

We can place the following code at any place where we would display the button.

<FORM>
<INPUT TYPE=”button” VALUE=”Make This Site Your Home Page” onClick=”this.style.behavior=’url(#default#homepage)’; this.setHomePage(’Page URL beginning with http:// here’);”>
</FORM>


All material @ copyrighted by chrisranjana.com. If you want to link to this article you are welcome to do so. Unauthorized publication is strictly prohibited. This developer tutorial website contains articles by Php programmers , Software developers, Mysql programmers and asp c# programmers. This website also contains ajax tutorials and advanced mysql sql stored procedures and functions tutorials and sample codes.