All posts by WhiteWind

About WhiteWind

I'm a Perl-PHP Developer from India. I'm a great fan of Wordpress & Perl.

How to make an event to occur automatically in webpage using jquery?

We have to use this when we need to initiate an event where user doesn’t like to click or make an action. To do this, use the following function:

$('#id').trigger('change'); // to run onchange event
$('#id').trigger('click'); // to run onclink event

Similarly we can run any event.

How to get values from the URL using javascript?

When we are in need to get values from the URL using java script as we get them using $_REQUEST[‘name’]; in PHP, $q->param(‘name’); in Perl etc. we can use the following function to get the values in java script :

function getUrlVars() {
    var vars = {};
    var parts = window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi, function(m,key,value) {
         vars[key] = value;
    });
    return vars;
}

To get the values we should call the above function as follows :

var val1=getUrlVars()["name1"];
alert(val1);

If the URL is http://ww.example.com/page.php?name1=value1&name2=value2&name3=value3, then the

var val1=getUrlVars()["name1"]; //value1
var val2=getUrlVars()["name2"]; //value2
var val2=getUrlVars()["name2"]; //value3

How to get the current URL using javascript?

The way to get the current URL using java script is as follows:

var thisUrl = window.location.href;
alert( thisUrl );

The output will be :

 http://www.example.com/page.php?name=value

How to get values from fileds which have same class name in jquery?

The way to do it is as follows:

var cpt= new Array();
$('.cpt_code').each(function() {
   console.log( $(this).val() );
   //alert($(this).val());
   cpt[x]=$(this).val();
   x++;
})

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.