Update multiple forms printed by a query

0

This form is printed the amounts of times according to the results, but ajax only catches me the first form, the other forms are sent to me jumping to the other page. Here is my code in Ajax. :)

<script language="javascript">// <![CDATA[
$(document).ready(function() {
    $().ajaxStart(function() {
        $('#loading').show();
        $('#result').hide();
    }).ajaxStop(function() {
        $('#loading').hide();
        $('#result').fadeIn('slow');
		$("#result").fadeOut(1000);
    });
   
    $('#h').submit(function() {
  
        $.ajax({
            type: 'POST',
            url: "ercc.php",
            data: $(this).serialize(),
            success: function(data) {
                $('#result').html(data);
            }
        })        
        return false;
    }); 
})
// ]]></script>
<?php $result = mysql_query("SELECT * FROM hclinico WHERE id = '$id' ");?>
<?php while($row = mysql_fetch_array($result)){?>
    
<form id="h" name="h" method="post" autocomplete="off" action="ercc.php">

<table id="m" width="30%" height="311" border="0">
  <tr>
    <td width="2%">&nbsp;</td>
    <td width="46%">&nbsp;</td>
    <td width="2%">&nbsp;</td>
    <td width="36%">&nbsp;</td>
    <?php echo "<td><a href='ppdf2.php?idd=".$row['idd']."' target='_blank'> <img src='print.png' width='20' height='20' /> </a></td>";  ?>
    <!--<td width="14%"><img src="print.png" width="20" height="20" /></td>-->
  </tr>
  <tr>
    <td>&nbsp;</td>
    <?php echo "<td><input type='hidden' name='idd[]' value='".$row['idd']."' /></td>";?>
    <td><div id="result"></div></td>
    <td>Sintomas</td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td><table width="20" border="0">
      <tr><td>Cédula</td>
        <td><input name="id[]" type="text" value=" <?php echo $row['id'] ?> "  readonly/>
        <label for="cédula"></label></td>
      </tr>
      <tr>
        <td>Talla</td>
        <td><label for="talla"></label>
          <input type="text" name="talla[]" value=" <?php echo $row['talla'] ?> "  required /></td>
      </tr>
      <tr>
        <td>F.C.</td>
        <td><label for="F.C."></label>
          <input type="text" name="fc[]" value=" <?php echo $row['fc'] ?> "  required /></td>
      </tr>
      <tr>
        <td>Fecha</td>
        <td><label for="fecha"></label>
          <?php echo " <input type='date' name='fecha[]' value='".$row['fecha']."' required/>";?>
          </td>
      </tr>
      <tr>
        <td>Hora</td>
        <td><label for="hora"></label>
          <input type="text" name="hora[]" value=" <?php echo $row['hora'] ?> "  required /></td>
      </tr>
      <tr>
        <td>P.A.</td>
        <td><label for="pa"></label>
          <input type="text" name="pa[]" value=" <?php echo $row['pa'] ?> "  required /></td>
      </tr>
      <tr>
        <td>F.R.</td>
        <td><label for="fr"></label>
          <input type="text" name="fr[]" value=" <?php echo $row['fr'] ?> "  required /></td>
      </tr>
      <tr>
        <td>Peso</td>
        <td><label for="peso"></label>
          <input type="text" name="peso[]" value=" <?php echo $row['peso'] ?> "  required /></td>
      </tr>
    </table></td>
    <td>&nbsp;</td>
    <?php $sint=$row['sint']; ?>
    <td><textarea name="textfield" cols="30" rows="12" name="sint[]"  type="text" value=" <?php $sint ?> " ><?php echo $sint; ?></textarea></td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    
    
    <td><input type="submit" name="mysubmit"  value="Actualizar" /></td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
</table>
<br />
  <label for="textfield3"></label>
</form>

<?php } 
    
asked by Leonardo 09.05.2017 в 08:59
source

1 answer

0

The id property must be unique per DOM, if you duplicate the form N times and reference $('#h').submit(function() { then only the first form the browser takes will be sent.

Use classes to obtain an array of elements in your jquery selector, these can be duplicated. Consider the following:

<form class="para_envio verde" id="h1"> ... </form>
<form class="para_envio rojo" id="h2"> ... </form>
<form class="para_envio azul" id="h3"> ... </form>

And in JQuery:

$('.para_envio').submit(function() {
  console.log(this);
}

As a result you have that each form will print in console the element that is in context when it is sent. What remains are the business rules you want to use.

    
answered by 10.05.2017 / 21:44
source