Javascript-форум (https://javascript.ru/forum/)
-   Events/DOM/Window (https://javascript.ru/forum/events/)
-   -   несколько form.submit() (https://javascript.ru/forum/events/67123-neskolko-form-submit.html)

laimas 29.01.2017 15:44

madam,
выбрасывайте все к чертовой матери, и если ваши картинки (семь форм условно) для того, чтобы отправить серверу два поля перед ней, то вам даже и одной формы не надо, а обрабатывать щелчки изображений, а в обработчике брать элементы по индексу этих изображений.

рони 29.01.2017 15:51

madam,
<!DOCTYPE html>

<html>
<head>
  <title>Untitled</title>
  <meta charset="utf-8">
  <style type="text/css">
  </style>
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>

  <script>
$(function() {
$("form").each(function(indx, form){
      $("img",form).on("click", function() {
 var amt=$('#t1',form).val();
 var prc=$('#t3', form).val();
 $('#t1',form).val('0');
 $('#t3',form).val('0');

 alert([amt,prc]) //для теста
 // далее сами
})

      });
});
  </script>
</head>

<body>
<form>
<input type="hidden" id="t1" name="am" value="100">
 <input type="hidden" id="t3" name="pm" value="200">
<img src="http://s7.hostingkartinok.com/uploads/images/2014/02/b33ecdff35171950f356df80a6a7c3dd.png" >
</form>
<form>
<input type="hidden" id="t1" name="am" value="12">
 <input type="hidden" id="t3" name="pm" value="43">
<img src="http://s7.hostingkartinok.com/uploads/images/2014/02/b33ecdff35171950f356df80a6a7c3dd.png" >
</form>


</body>
</html>

laimas 29.01.2017 16:21

рони,
зачем плодить кучи форм, если они не отправляются естественным образом?

<html>
<head>
  <meta charset="utf-8">
  <script src="http://code.jquery.com/jquery-1.9.1.js"></script>

 <script>
$(function() {
    var inp = $('form').on('click', 'img', function() {
        var e = inp.slice(this.id * 2, this.id * 2 + 2);
        alert(e.eq(0).val() +'/'+ e.eq(1).val())
        //$.post("api.php",{type:'1',am:e.eq(0).val(),pm:e.eq(1).val()}, ...)
    }).find('input');
});
</script>
</head>
<body>
<form>
<input type="hidden" name="am" value="12">
<input type="hidden" name="pm" value="43">
<img src="" id="0" width="50" height="20"/>
<input type="hidden" name="am" value="92">
<input type="hidden" name="pm" value="11">
<img src="" id="1" width="50" height="20"/>
<input type="hidden" name="am" value="67">
<input type="hidden" name="pm" value="78">
<img src="" id="2" width="50" height="20"/>
</form>
</body>
</html>

madam 29.01.2017 16:22

Цитата:

Сообщение от рони (Сообщение 442640)
madam,
<!DOCTYPE html>

<html>
<head>
  <title>Untitled</title>
  <meta charset="utf-8">
  <style type="text/css">
  </style>
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>

  <script>
$(function() {
$("form").each(function(indx, form){
      $("img",form).on("click", function() {
 var amt=$('#t1',form).val();
 var prc=$('#t3', form).val();
 $('#t1',form).val('0');
 $('#t3',form).val('0');

 alert([amt,prc]) //для теста
 // далее сами
})

      });
});
  </script>
</head>

<body>
<form>
<input type="hidden" id="t1" name="am" value="100">
 <input type="hidden" id="t3" name="pm" value="200">
<img src="http://s7.hostingkartinok.com/uploads/images/2014/02/b33ecdff35171950f356df80a6a7c3dd.png" >
</form>
<form>
<input type="hidden" id="t1" name="am" value="12">
 <input type="hidden" id="t3" name="pm" value="43">
<img src="http://s7.hostingkartinok.com/uploads/images/2014/02/b33ecdff35171950f356df80a6a7c3dd.png" >
</form>


</body>
</html>

Спасибо огромное


Часовой пояс GMT +3, время: 21:21.