jquery - javascript validation for dynamic element -


How can I validate dynamically-generated text inputs?

I have a "Add more" link that creates new ones, and a link to delete them.

>

I understand how to dynamically form a form Adding the input from, and adding validation rules for the jQuery validation plugin together.

In my example, this was an order form for the helmet:

  // Each set of helmet input is unique ID function newHelmetInputs (i) {var inputSet = '' ; InputSet + = '& lt; Label = "helmet" + i + 'color' & gt; Helmet '+ i +' color & lt; / Label & gt; InputSet + = '& lt; Input id = "helmet" + I + 'color "name =" helmet [' + I + '] [color] "/> gt; inputset + =' & lt; label =" helmet "+ i + 'size" Gt; Helmet '+ i +' size & lt; / Label & gt; InputSet + = '& lt; Input id = "helmet" + i + 'size "name =" helmet [' + I + '] [shape] "/> return inputet; // in fact click them on page $ (' # adhelmet ') (Function () {var i = nextNumber (); // nextNumber () is a closure - see my blog for details newinputs = newHelmetInputs (i); // IDI is used in $ (this) above. Before (newInputs); ('#helmet' + i + 'size'). Rule ('add', {number: true}); // match verification rule};  

The blog post comes in more detail, and also How to process it with PHP.

For the requirement that at least two text boxes will be filled. I have written one for this, and he says, "either in this section field Fill in at least x, or leave the section completely. "

For example, if your form orders people sandwich, and in each sandwich, the bread and an input You can dynamically add fields to several sandwiches Because they want to order, they do not have to fill anything for sandwich # 2, but if they do, then they have to give both roti and filling types.


Comments

Popular posts from this blog

sql - dynamically varied number of conditions in the 'where' statement using LINQ -

asp.net mvc - Dynamically Generated Ajax.BeginForm -

Debug on symbian -