Skip to main content

3 posts tagged with "JavaScript"

View All Tags

The entity name must immediately follow the '&' in the entity reference. Blogspot template

· One min read
Sandeep Bhardwaj

Some times when we write some JavaScript on blogspot template we got this error
**"The entity name must immediately follow the '&' in the entity reference."**This error come if we have some and condition in our JavaScript like

if(document.getElementById && !document.all){  
// do something here

}

Here is the simple solution of this just replace the & with &.

if(document.getElementById && !document.all){  
// do something here

}

Post you valuable comment if this solution works for you.

Create file type input using textbox and simple button

· One min read
Sandeep Bhardwaj

Some times we have requirement to create a file type input in HTML with using simple textbox and a simple button for browse functionality. I search a lot on Google to achieve this functionality but there is no option available in javascript or in jQuery to open file dialog using a simple button.

Then i used a simple trick to achieve this.

<input name="browse" style="display: none;" type="file">                                                   
<input name="fileInput" maxlength="255" type="text">
<input onclick="browse.click();fileInput.value=browse.value;" value="Browse.." type="button">

Trim method in JavaScript

· One min read
Sandeep Bhardwaj

We can use String.replace method to trim a string in javascript.

//method for trim a complete string like "  Hello World   "  
function trim(str) {
return str.replace(/^\s+|\s+$/g,"");
}

//method for left trim a string like " Hello World"
function leftTrim(str) {
return str.replace(/^\s+/,"");
}

//method for right trim a string like "Hello World "
function rightTrim(str) {
return str.replace(/\s+$/,"");
}