javascript - jQuery PHP foreach -


<? foreach($words $word): ?> <li>     <form action="javascript:alert( 'success!' );">       <div>         <input type="text"/>         <input type="submit"/>       </div>     </form> </li> <? endforeach; ?>   <script> $(document).ready(function(){     $( "form" ).submit(function( event ) {     if ( $( "input:first" ).val() === "<?php $word['word']['words'] ?>" ) {         $( spans ).text( "validated..." ).show();          return;       }})   }); </script> 

this script should compare every words input 'words' (table in mysql), when write in input , press submit - working submit. how create unique form , input each word form?

i don't think of examples here work, because none compares input value word of foreach loop. try this:

<? foreach($words $word): ?> <li>   <form data-word="<? echo $word; ?>">     <div>       <span class="validation"></span>       <input class="word" type="text">       <input type="submit">     </div>   </form> </li> <? endforeach; ?>  <script> $(document).ready(function() {   $('form').submit(function(event) {     var $form = $(this),       value = $form.find('.word').val(),       word = $form.data('word'),       valid = word === value,       message = valid ? 'validated...' : 'not valid.';      $form       .find('.validation')       .html(message)       .show();      event.preventdefault();   }); }); </script> 

Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -