jQuery plugin for form validation
Resources:
http://formvalidator.net/
by Rolf van Gelder | CAGE Web Design, Eindhoven
jQuery plugin for form validation
Resources:
http://formvalidator.net/
General:
jQuery(document).ready(function() { // Initialize some vars (...) // Declare actions: jQuery("#loader").show(); }); // IF YOU WANT TO WAIT TILL ALL IMAGES ARE LOADED USE: jQuery(window).load(function() { // Initialize some vars (...) // Declare actions: jQuery("#loader").show(); });
Ajax get:
jQuery.get( "ajax_server.php", { action: "give_address", postalcode: postalcode, housenumber: housenumber} ) .done(function( data ) { if(data.length>1) { var tmp = data.split("_"); jQuery("#street").val(tmp[0]); jQuery("#city").val(tmp[1]); } else alert('Invalid combination'); });
Change the source of an image:
jQuery("#icon_save").attr("src", "icon_save.png");
Color odd and even rows in a table dynamically:
jQuery('li:visible:even').css("background-color", "#f7fbfc"); jQuery('li:visible:odd').css("background-color", "#fff"); - or - jQuery("tr:even").css("background-color", "#eeeeee"); jQuery("tr:odd").css("background-color", "#ffffff");
Dynamically add a table row at the end of a table:
jQuery("#my_table tr:last").after('<tr><td>new col 1</td><td>new col 2</td></tr>');
Delete all table rows except first
jQuery(document).ready(function() { jQuery("#my_table").find("tr:gt(0)").remove(); });
Disable / enable a form field:
jQuery("input").prop("disabled", true); jQuery("input").prop("disabled", false);
Get / set value of a form field:
var lastName = jQuery("#lastname").val(); jQuery("#lastname").val("Gelder");
Get / set the state of a check box:
var isChecked = jQuery("#cb").prop("checked"); jQuery("#cb").prop("checked", false); jQuery("#cb").prop("checked", true);
Check if at least ONE checkbox is checked and count the number of checked boxes:
<input id="cb1" class="mycb" name="files[]" type="checkbox" value="Y"> <input id="cb2" class="mycb" name="files[]" type="checkbox" value="Y"> <script> if(jQuery("input[name='files[]']").is(":checked")) alert('At least ONE checked!); alert('Number of checked boxes: '+jQuery('.mycb:checked').size()); </script
Show / hide a division:
jQuery("#diva").show(); jQuery("#diva").hide(); jQuery("#diva").fadeIn(1000, function() { alert('Done fading in!') }); jQuery("#diva").fadeOut(1000, function() { alert('Done fading out!') });
Submit a form with Ajax, using jQuery.
Examples:
Resources:
http://malsup.com/jquery/form/