Tag Archives: Java Scripts

How to handle the resets on loss of focus while using autocomplete combobox in IE?

You can try using the jQuery UI autocomplete’s open and close event to control your textbox’s blur event. When the autocomplete is open you disable the blur event and when it close you enable your blur event again.

var disable=false;

$( "#tags" ).autocomplete({
  source: availableTags,
  open: function(event, ui) { disable=true },
  close: function(event, ui) {
    disable=false; $(this).focus();
  }
}).blur(function() {
  if(!disable) {
    alert('blur');
  }
});

Instead of

alert('blur');

write the code that you need to workout when exactly the focus of the input filed is lossing.

I personly tested and used it.

How can I get last characters of a string using JavaScript?

You’ll want to use the Javascript string method .substr() combined with the .length property.

var id = "ctl03_Tabs1";
var lastFive = id.substr(id.length - 5); // => "Tabs1"
var lastChar = id.substr(id.length - 1); // => "1"

This gets the characters starting at id.length – 5 and, since the second argument for .substr() is omitted, continues to the end of the string.

If you’re simply looking to find the characters after the underscore, you could use this:

var tabId = id.split("_").pop(); // => "Tabs1"

This splits the string into an array on the underscore and then “pops” the last element off the array (which is the string you want).

innerHTML not working in Internet Explorer(IE)

We may see that we don’t get proper output in IE when we try to use

document.getElementById('my_id').innerHTML="mm";

This mainly happens in the case we try to implement innerHTML into the select tag. The way I recommend to overcome this situation is to use jquery. We can write the content in jquery as follows:

$('#my_id').html("<option value='mm'>mm</option>");

I had tested it and saw that it’s working.

How to implement “select all” check box using js in HTML?

It can be implemented as follows…

<input id="my_selectall" style="box-shadow: 0px 0px 0 0; width: auto;" onclick="mycheck()" type="checkbox" /> Sl No.
<input style="box-shadow: 0px 0px 0 0; width: auto;" type="checkbox" name="case" value="1" /> 1
<input style="box-shadow: 0px 0px 0 0; width: auto;" type="checkbox" name="case" value="2" /> 2
<input style="box-shadow: 0px 0px 0 0; width: auto;" type="checkbox" name="case" value="3" /> 3
<input style="box-shadow: 0px 0px 0 0; width: auto;" type="checkbox" name="case" value="4" /> 4
<script type="text/javascript">
    function mycheck() {
        var source=document.getElementById('my_selectall');
        checkboxes = document.getElementsByName('case');
        for(var i=0, n=checkboxes.length;i<n;i++) {
            checkboxes[i].checked = source.checked;
        }
    }
</script>

Zooming image with jquery

Check the following links to see how it work

To download it please click the below links