<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>jQuery &#8211; MeghRaj TechnoSoft &#8211; Web, App, E-commerce Development  Agency In India.</title>
	<atom:link href="https://www.meghrajtechnosoft.com/jquery/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.meghrajtechnosoft.com</link>
	<description></description>
	<lastBuildDate>Tue, 22 Dec 2020 13:37:30 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=5.5.15</generator>

<image>
	<url>https://www.meghrajtechnosoft.com/wp-content/uploads/2020/10/fevecon.png</url>
	<title>jQuery &#8211; MeghRaj TechnoSoft &#8211; Web, App, E-commerce Development  Agency In India.</title>
	<link>https://www.meghrajtechnosoft.com</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>JQUERY: VALIDATE MULTIPLE FIELDS WITH THE SAME NAME</title>
		<link>https://www.meghrajtechnosoft.com/jquery-validate-multiple-fields-with-the-same-name/</link>
					<comments>https://www.meghrajtechnosoft.com/jquery-validate-multiple-fields-with-the-same-name/#respond</comments>
		
		<dc:creator><![CDATA[admin]]></dc:creator>
		<pubDate>Tue, 08 Dec 2020 13:11:29 +0000</pubDate>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[jQuery]]></category>
		<guid isPermaLink="false">https://www.meghrajtechnosoft.com/?p=17548</guid>

					<description><![CDATA[<p>Sometimes we need to validate an array of input elements: For example – Select any abc abc abc abc Select any xyz xyz xyz xyz Now we will use jquery validation plugin jquery.validate.js for validating the form. The condition will [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://www.meghrajtechnosoft.com/jquery-validate-multiple-fields-with-the-same-name/">JQUERY: VALIDATE MULTIPLE FIELDS WITH THE SAME NAME</a> appeared first on <a rel="nofollow" href="https://www.meghrajtechnosoft.com">MeghRaj TechnoSoft - Web, App, E-commerce Development  Agency In India.</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>Sometimes we need to validate an array of input elements: For example –</p>



<pre><code><form name="checkform" class="form-control" id="checkform" method="post" action="">
    <select name="field_name[]" id="field_1">
        <option value="">Select any</option>
        <option value="1">abc</option>
        <option value="2">abc</option>
        <option value="3">abc</option>
        <option value="4">abc</option>
    </select>
  
    <select name="field_name[]" id="field_2">
        <option value="">Select any</option>
        <option value="5">xyz</option>
        <option value="6">xyz</option>
        <option value="7">xyz</option>
        <option value="8">xyz</option>
    </select>
  
<input class="submit" value="Submit" type="submit">
</form></code></pre>



<p>Now we will use jquery validation plugin jquery.validate.js for validating the form. The condition will be that user will have to choose field_name from each dropdown. The script for validation will be as below –</p>



<pre><code><script type="text/javascript">
    $().ready(function() {
        $("#checkform").validate({
            rules: {
                "field_name[]": "required"
            },
            messages: {
                "field_name[]": "Please select field option",
            }
        });
    });></code></pre>



<p>Now the problem is that the jquery.validate.js only validates the first element of field_name[]. So, we need to modify it a little bit.</p>



<p>In jquery.validate.js, we can find a function named checkForm,<br>just comment out the org code<br>we have to modify it as below:</p>



<pre><code>// checkForm: function() {
    //  this.prepareForm();
    //  for ( var i = 0, elements = (this.currentElements = this.elements()); elements[i]; i++ ) {
    //      this.check( elements[i] );
    //  }
         
    //  return this.valid();
// },
 
checkForm: function() {
    this.prepareForm();
        for ( var i = 0, elements = (this.currentElements = this.elements()); elements[i]; i++ ) {
            if (this.findByName( elements[i].name ).length != undefined && this.findByName( elements[i].name ).length > 1) {
                for (var cnt = 0; cnt < this.findByName( elements[i].name ).length; cnt++) {
                    this.check( this.findByName( elements[i].name )[cnt] );
                }
            } 
            else {
                this.check( elements[i] );
            }
        }
        return this.valid();
},</code></pre>
<p>The post <a rel="nofollow" href="https://www.meghrajtechnosoft.com/jquery-validate-multiple-fields-with-the-same-name/">JQUERY: VALIDATE MULTIPLE FIELDS WITH THE SAME NAME</a> appeared first on <a rel="nofollow" href="https://www.meghrajtechnosoft.com">MeghRaj TechnoSoft - Web, App, E-commerce Development  Agency In India.</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.meghrajtechnosoft.com/jquery-validate-multiple-fields-with-the-same-name/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
