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

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

java - Digest auth with Spring Security using javaconfig -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -