Showing posts with label Javascript. Show all posts
Showing posts with label Javascript. Show all posts

Friday, February 10, 2012

Jquery UI -Autocomplete with Server side data

Good article
Example inside Document.ready
    $('controlname').autocomplete({
        source: function (request, response) {
            $.ajax({
                type: "POST",
                url: "pagename/methodname" , //"search.aspx/getClientNames"
                data: "{}",
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                // This explicitly disables any browser caching.
                dataFilter: function (data) { return data; },
                success: function (data) {
                    response($.map(data.d, function (item) {
                        return {
                            value: item
                        }
                    })) // response
                }, // success
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    alert(textStatus);
                }
            }); // ajax
        },
        minLength: 2
    });// autocomplete

Thursday, March 31, 2011

A guide to select option elements using jQuery

A guide to select option elements using jQuery


Basics selection
Select element by id : $("#elementid")
Select all select elements : $("select")
Select all select elements by class : $("select.classname")
Select all options from a select element : $("#elementid option")

Filters

Select the first option : $("#elementid option:first")
Select the last option : $("#elementid option:last")
Select the option at a particular index (variant 1) : $("#elementid option:eq(2)")
Select all options that have a value attribute set : $("#elementid option[value]")
Select element by name : $("select[name=elementname]")

Execute a function on each matched element
$("#elementid option").each(function() {
alert("hey raj"); })

Number of matched select elements : $("select").size()
Number of options in a particular select element : $("#elementid option").size()
Select an option at a particular index (variant 2) : $("#elementid option").eq(1)
Get the index of the selected option (variant 1) : $("#elementid option").index($("#elementid option:selected")))
Add a class to matched select element : $("#elementid").addClass("inputs")

Remove a class from matched select element : $("#elementid").removeClass("inputs")

Get inner HTML of matched select : $("#elementid").html()
Remove all options from matched select : $("#elementid").html("")
Get the selected text of matched select : $("#elementid option:selected").text()
Set the text of a matched option : $("#elementid option:eq(2)").text("Amy")
Get the selected value of matched select : $("#elementid").val()

Add options to the end of select element : $("#elementid").append("")
Add options to the start of select element : $("#elementid").prepend("")

Getting values when an option is selected
$("#elementid").change(function()
{ alert($(this).val());
alert($(this).children("option:selected").text()); })

To eleminate the first option
if ($('#elementid option').index($('#elementid option:selected')) != 0)
{ }

Wednesday, January 19, 2011

Javascript:Remove the last character in a string

var str = 'Dear Raj!';
var newStr = str.substring(0, str.length-1);
//alert(newStr); 
but the simplest is
str.slice(0,-1) 

Monday, January 10, 2011

JQuery-Remove Duplicates from an Array

function uniqueArray(myarray)// to remove the duplicates from an Array
{
//var vals = this;
var uniques = [];
for(var i=myarray.length;i--;){
var val = myarray[i];
if($.inArray( val, uniques )===-1){
uniques.unshift(val);
}
}

return uniques;
}

Thursday, January 6, 2011

JQuery-Create Dropdown from Array

$.each(myArray,function(i,j){
$("<option value=" +i+ ">" +j+ "</option>").appendTo('#ddname');
});

Monday, October 20, 2008

To debug JavaScript in VS.NET

  1. Open Microsoft Internet Explorer.
  2. On the Tools menu, click Internet Options.
  3. On the Advanced tab, locate the Browsing section, and uncheck the Disable script debugging check box, and then click OK.
  4. Close Internet Explorer.
    In your JavasSript function add the keyword debugger . This causes VS.NET to switch to debug mode when it runs that line.
    Run your ASP.Net application in debug mode.
    That's all there is to it.