Thursday, April 16, 2015

jquery check valid emailid

  if (!(txtEmail == "" || txtEmail == null || txtEmail == undefined)) {

                var email = /\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/;
                if (!email.test(txtEmail)) {
                    $('#sp').text("Please enter valid email address.")
                    $('#sp').show();
                    validateFlag = false;
                }
                else {
                    $('#sp').hide();
                }

            }

jQuery/Javascript function to clear all the fields of a form [duplicate]

$('#myForm').trigger("reset");

javascript ajax parameters

1) async -

A Boolean value indicating whether the request should be handled asynchronous or not. Default is true

2) contentType - 

The content type used when sending data to the server. Default is: "application/x-www-form-urlencoded"

3) data -

Specifies data to be sent to the server

4) error(xhr,status,error) -

A function to run if the request fails.

5) success(result,status,xhr

A function to be run when the request succeeds

6) type 

Specifies the type of request. (GET or POST)

7) url -

Specifies the URL to send the request to. Default is the current page

 var model = { Id: ID}
  $.ajax({
                url: baseUrl + '/Case/Get',
                type: 'POST',
                data: JSON.stringify(model),
                async: false,
                contentType: "application/json; charset=utf-8",
                success: function (data) {
                                                                  
                    }

                },
                error: function (x, y, z) {
                    alert(x + '\n' + y + '\n' + z);
                }
            });

jquery bind text to span tag

 $get('spnDepartment').innerHTML = "IT";

 <span id="spnDepartment" ></span>

Wednesday, April 15, 2015

asp.net listbox select items by value jquery

  $.each(data[0].Work.split(","), function (i, e) {

                            $("#<%=lb.ClientID%> option[value='" + e + "']").prop("selected", true);

                        });

jQuery event.preventDefault() Method

The event.preventDefault() method stops the default action of an element from happening.
For example:
  • Prevent a submit button from submitting a form
  • Prevent a link from following the URL

$("a").click(function(event){
    event.preventDefault();
});

Prevent a link from opening the URL:

Javascript Ajax Syntax

 function Create() {

     var parameters = {
DepartmentId: hddepartmentId
                                 };

            $.ajax({
                type: "POST",
                contentType: "application/json; charset=utf-8",
                url: baseUrl + 'Case/Create',
                data: JSON.stringify(parameters),
                dataType: "json",
                success: function (data) {
                 alert("Success");
                },
                error: function (result) {
             
                    //alert("Error in case creation");
                    //alert(result);
                }
            });
        }