Validate input fields after changing input values with jQuery or echoing values with PHP -
i'm using jquery validation plugin. have simple function copies 1 input's value input.
function sameasshipping() { $('#billingfirstname').val($('#firstname').val()); }
i validate newly copied input values using valid() method. i'm trying call valid() method if input's value isn't blank.
$(document).ready(function(){ $(":input, select").each(function() { if(!$(this).val() === "") $(this).valid(); }); });
along manipulating input values jquery, if form submitted , there error, echo submitted values. these validate these fields on load, however, if there value in input.
<input type="text" id="billingfirstname" name="billingfirstname" class="required" placeholder="first name" value="<?php if(isset($_session['firstname'])){echo $_session['firstname'];} ?>">
dynamically created dom objects cannot selected javascript directly. need select static element existed before dom manipulation.
here's example:
$(document).ready(function(){ $("body :input, select").each(function() { if(!$(this).val() === "") $(this).valid(); }); });
body element static (not created) javascript , can selected. tehre can navigate element normal. not need use body. element static html or created back-end programming language work.
alternatively use livequery plugin jquery.
Comments
Post a Comment