tags:

views:

46

answers:

1

i use jquery.form to send a form, but in may case below how use this jquery plugin

$('#htmlForm').ajaxForm({ 
 target: '#htmlExampleTarget', 
 success: function() { 
  $('#htmlExampleTarget').fadeIn('slow');
  $('#htmlForm').hide();
 } 
});

for($i=1;$i<= 10;$i++){

//form $1

form name="form$i" action="blabla.php"

input type="text" name="name$i" />

input type="text" name="name$i" />

input type="submit" name="submit" /

}

A: 

Use class instead of id and loop through the forms. For the target take an id like #htmlExampleTarget1.

var i = 1;
$('.htmlForm').each(function () {
   var object = $(this);
   object.ajaxForm({
      target: '#htmlExampleTarget' + i, 
      success: function() { 
         $('#htmlExampleTarget' + i).fadeIn('slow');
         object.hide();
       }
   });
   i++;
});
stefita
your code doesn't work...
Agus Puryanto
how did you integrated, did you changed your php code respectively and what exactly didn#t work (i.e. js error output)?
stefita
<script>$(document).ready(function(){ var i = 1; $('#htmlForm').each(function () { var object = $(this); object.ajaxForm({ target: '#htmlExampleTarget' + i, success: function() { $('#htmlExampleTarget' + i).fadeIn('slow'); object.hide(); } }); i++; });});</script><?php$i=1;foreach ($data as $item) { <div id="htmlExampleTarget<?php echo $i;?>"></div> <form id="htmlForm" method="post" action="sendmail.php"> //form here </form>}?>or you can view the demo at easyhired.com
Agus Puryanto
only first form is working, another form not.
Agus Puryanto
you can view the code and demo at http://easyhired.com/yahoo/index.php
Agus Puryanto
Yes, because you are using an id not a class, as I showed in my example! Change `<form id="htmlForm" ...>` to `<form class="htmlForm">` and your script from `$('#htmlForm').each ...` to `$('.htmlForm').each ...` and try again.
stefita
Yes, is 100% working. Thank you stefita
Agus Puryanto