How to declare variable in JavaScript

{0 Comments}

When it comes to declare the variable in JavaScript it is much more similar like most popular programming languages. Here we have to use var keyword which automatically takes the data type of the variable on assigning it which is much more similar to php. After  var keyword all you have to give a name …

Read More…

How to disable link in JavaScript

{0 Comments}

You can disable the link in JavaScript by getting the element id of the link or get the element tag which is here is <a> tag and then apply the property to it.  Whose syntax will look like as follows:  Javascript |  copy code |? 1function disable() {2 document.getElementById( "linkID" ).disabled = ‘true’;3 //or4 document.getElementsByTagName("a").disabled=’true’;5 }6 Or you can use …

Read More…

How to disable right click in JavaScript

{0 Comments}

We have already written a script to disable copy and paste in the browser. Which also disable right click of the browser too so you can use the same JavaScript to disable right click which is as follows   Javascript |  copy code |? 01 <script language="javascript"> 02function click() { 03return false;} 04function click1(){if (event.button==2) {return false; }} 05function CtrlKeyDown(){ 06if …

Read More…

How to disable checkbox in JavaScript

{0 Comments}

You can disable checkbox in JavaScript similarly like you disable textbox in JavaScript. All you have to get the id of the checkbox then set the disable property to true as we done in case of textbox so syntax will be as follows   Javascript |  copy code |? 1<script type="text/javascript">2 function disable() {3 document.getElementById( "CheckboxID" ).disabled = ‘true’;4 }5 6 </script>7

Read More…

How to declare array in JavaScript

{0 Comments}

You can declare array in JavaScript in three ways. First one using JavaScript array constructor, second is literal notation, third way is calling method with array return type. Following is the syntax to declare JavaScript array with array constructor here new keyword is to define array in memory  Javascript |  copy code |? 1var abcarray = new Array();2 var abcarray1= …

Read More…

How to break a line in JavaScript

{0 Comments}

To break a line in JavaScript we can find space or a special character with the help of regular expression then we can replace the same with </br> tag which will actually break the line of the particular message so the sample code for that is as follows:  Javascript |  copy code |? 1var div = document.getElementById(’message’).innerHTML = text.replace(/(\r\n)|(\n)/g,"<br />")

Read More…

How to break a string in JavaScript

{0 Comments}

Breaking a string is usually called as splitting a string we can split a string depending on the condition or delimiter. You can know some more how to break a string in following article, click on the link. After splitting the string, you will return the result in form of array. how to split a …

Read More…

How to break a loop JavaScript

{0 Comments}

To break a loop in JavaScript we can use break statement to break a loop, you have to write break with “;” this will break the excising loop of JavaScript you can use same in while and for loop to. like in following example  Javascript |  copy code |? 1 for (i=0;i<10;i++)2 {3 if (i==3)4 {5 break;6 } 7do some …

Read More…

How to disable a textbox using JavaScript

{0 Comments}

To disable a text box using JavaScript you can following syntax which will help you disable textbox.  Javascript |  copy code |? 1<script type="text/javascript">2 function disable() {3 document.getElementById( "Text1" ).disabled = ‘true’;4 }5 6 </script>  HTML |  copy code |? 1<div >2 <input id="Text1" type="text" />3 </div>4 <input id="Button1" type="button" value="hide" onclick="disable()" />

Read More…

How to trim a string in JavaScript

{0 Comments}

In latest IE browser has a inbuilt function to trim the string you only have to call trim () function.  And if you are using another version then you can use following trim syntax in the JavaScript which will help you to trim strings.   Javascript |  copy code |? 1String.prototype.trim=function(){return this.replace(/^\s\s*/, ”).replace(/\s\s*$/, ”);};2

Read More…