Tuesday, January 17, 2012

To get select radiobutton value using its name

Use like this

$('input:radio[name=radReason]').change(function() {
  varSelval = $("input:radio[name=radReason]:checked").val();
});

Friday, January 13, 2012

Hide/Remove dialogbox close button in title

closeOnEscape: false,
open: function (event, ui) { $(".ui-dialog-titlebar-close").hide(); },

------------------
$("#popUpOne").dialog({
                autoOpen: false,
                height: 660,
                width: 740,
                modal: true,
                closeOnEscape: false,
                open: function (event, ui) { $(".ui-dialog-titlebar-close").hide(); },
                buttons: {
                    "SAVE": function () {
                        SaveFunction();
                    },
                    CANCEL: function () {
                        $(this).dialog("close");
                    }
                },
                close: function () {
                    allFields.val("").removeClass("ui-state-error");
                }
            });

Wednesday, January 11, 2012

Auto Complete textbox

------------------------ASPX PAGE--------------------------------
var AutoTestID = 0;
$(document).ready(function(){


        $("#txtTestName").autocomplete({
                source: function (request, response) {
                    TestID= 0;
                    $.ajax({
                        url: "ReferalIntakeOrg.aspx/GetPatientNameAutoSugg",
                        data: "{ 'TestName': '" + request.term + "','PhoneNo':'"+ $("#txtPrimaryNo").val()+"'}",
                        dataType: "json",
                        type: "POST",
                        contentType: "application/json; charset=utf-8",
                        dataFilter: function (data) { return data; },
                        success: function (data) {
                            response($.map(data.d, function (item) {
                                return {
                                    label: item.Name,
                                    value: item.Name,
                                    Id: item.Id
                                }
                            }))
                        }
                    });
                },
                minLength: 1,
                select: function (event, ui) {
                    AutoTestID= ui.item.Id;
                    FillTestDetails(AutoTestID);
                }
            });
}); //document.ready ends here




--------------ASPX.CS PAGE----------------
[WebMethod]
        public static List<AutoFillItem> GetPatientNameAutoSugg(string PatientName, string PrimaryContactNo)
        {
            List<AutoFillItem> list = new List<AutoFillItem>();
            ServiceReference1.TestWCFServiceClient oITestWCFService = new ServiceReference1.TestWCFServiceClient();
            DataSet ds = oITestWCFService.GetTestNameAutoSugg(TestName, PhoneNo);

            foreach (DataRow tr in ds.Tables[0].Rows)
            {
                AutoFillItem item = new AutoFillItem();
                item.Id = tr[0].ToString();
                item.Name = tr[1].ToString();

                list.Add(item);
            }
            return list.ToList();
        }

------------------------ADD A CLASS AutoFillItem.cs------------------
//declare our needs
 public string Id;
 public string Name;

Add days to selected date


 $('#txttFrom').change(function () {
                var date2 = $('#txtFrom').datepicker('getDate', '+1d');
                date2.setDate(date2.getDate() + 60);
                $('#txtTo').datepicker('setDate', date2);
            });

------------OR--------------
  $('#txtDate').datepicker({ onSelect: function (dateStr) {
            var date = $(this).datepicker('getDate');
            if (date) {
                date.setDate(date.getDate() + 1);
                // Do something with date + 1
            }
        }
        });

Wednesday, January 4, 2012

Parent Child Selector

The syntax for finding children which are direct descendants of an element looks like this:

$("div > a")

This selector will find all links which are the direct child of a div element. Replacing the greater-than symbol with a simple space will change this to match all links within a div element, no matter if they are directly related or not:

$("div a")

eg : 

<div id="divTest1">
        <b>Bold text</b>
        <i>Italic text</i>
        <div id="divTest2">
                <b>Bold text 2</b>
                <i>Italic text 2</i>
                <div>
                        <b>Bold text 3</b>
                </div>
        </div>
</div>
<script type="text/javascript">

$("#divTest1 > b").css("color", "blue");
</script>
 
 
************************
 //here  bold tags blue if they are directly descending from the divTest1:
$("#divTest1 > b").css("color", "blue");
 
// //here  all the bold tags colour green within the divTest1:
$("#divTest1  b").css("color", "green");