Tuesday, May 12, 2015

playing with jQuery

To Read the value of input textbox-

var batchId = $('input[name=empname]').val();
Where empname is the name of the input text field


To Read the value of select box/drop down-

var batchId = $('select[name=empdept]').val();
Where empdept is the name of the select or drop down field


To submit the form

$("form[name='employeeForm']").submit(); 
 where employeeForm is the name of form


To set value of hidden field

$('input[name=empCd]').val(valueVar);
where empCd is the name of the hidden field and valueVar is the value to be assigned


To execute any javascript code on page load

$(document).ready(function() {
//code goes here
});
Write javascript stament inside ready function which gets executed after successful page load


To show/hide fields or div elements


$("#fieldId").show();
$("#
fieldId").hide();
where fieldId is the id of the form field or any html element


To disable form field

$("#fieldId").attr("disabled",true);

where fieldId is the id of the form field or any html element