Необходимо чтобы постом приходили разные значения двух jquery скриптов
А выходит так, будто только один из скриптов отрабатывает и введёные значения приходят с именами второго скрипта.
<table border='1' cellspacing='1' cellpadding='6' width='100%' id="table_container"> </table> <script type="text/javascript"> var total = 0; function add_new_image(a){ total++; $('<tr>') .attr('id','tr_image_'+total) .css({lineHeight:'0px'}) .append ( $('<td>') .attr('id','td_title_'+total) .css({width:'5%'}) .append( $('<input type="text"/>') .css({width:'100%'}) .attr('id','1'+total) .attr('name','a[]') ) ) .append( $('<td>') .attr('id','td_ name_'+total) .css({width:'50%'}) .append( $('<input type="text"/>') .css({width:'100%'}) .attr('id','5'+total) .attr('name','invent_numbe[]') ) ) .append( $('<td>') .attr('id','td_ name_'+total) .css({width:'35%'}) .append( $('<input type="text"/>') .css({width:'100%'}) .attr('id','5'+total) .attr('name','invent_numbe[]') ) ) .append( $('<td>') .attr('id','td_ name_'+total) .css({width:'10%'}) .append( $('<input type="text" />') .css({width:'100%'}) .attr('id','5'+total) .attr('name','invent_number10[]') ) ) .appendTo(a); } $(document).ready(function() { add_new_image('#table_container'); }); </script> <script type="text/javascript"> var totalb = 1000; function add_new_image(b){ totalb++; $('<tr>') .attr('id','tr_image_'+totalb) .css({lineHeight:'0px'}) .append ( $('<td>') .attr('id','td_title_'+totalb) .css({width:'5%'}) .append( $('<input type="text"/>') .css({width:'100%'}) .attr('id','1'+totalb) .attr('name','a1[]') ) ) .append( $('<td>') .attr('id','td_ name_'+totalb) .css({width:'50%'}) .append( $('<input type="text"/>') .css({width:'100%'}) .attr('id','5'+totalb) .attr('name','invent_number2[]') ) ) .append( $('<td>') .attr('id','td_ name_'+totalb) .css({width:'35%'}) .append( $('<input type="text"/>') .css({width:'100%'}) .attr('id','5'+totalb) .attr('name','invent_number3[]') ) ) .append( $('<td>') .attr('id','td_ name_'+totalb) .css({width:'10%'}) .append( $('<input type="text" />') .css({width:'100%'}) .attr('id','5'+totalb) .attr('name','invent_number4[]') ) ) .appendTo(b); } $(document).ready(function() { add_new_image('#table_container2'); }); </script> <table border='1' cellspacing='1' cellpadding='6' width='100%' id="table_container"> </table> |
в хроме есть фаербаг (и не только в хроме), вызывается f12.
открываем вкладку network, перезагружаем страницу. можно все отчистить дабы не мешалось все (рядом с кнопочкой all, documents). и делайте запрос на сервер. после чего должна появиться соответствующая строка о запросе. нажимайте на нее и смотрите, какой ответ вы получили |
Вы наверное меня не так поняли, мне эти значения нужны для записи в БД MySql, скрипт весьма удобный, а так как появилась необходимость вводить две разные таблицы по отдельности, я попытался разделить его на две части, чтобы из каждой части брать уникальные значения для записи в Mysql. А в данный момент скрипт выводит только одну часть.
Пример как выводит сейчас: [a1] => Array ( [0] => [1] => [2] => ) [invent_number2] => Array ( [0] => [1] => [2] => ) [invent_number3] => Array ( [0] => [1] => [2] => ) [invent_number4] => Array ( [0] => [1] => [2] => ) |
давайте сначала, ибо я вас не пойму. у вас есть 2 таблицы в бд. и вы хотите для начала их вывести. и подгрузка данных идет аякс запросом через пост. и идет 2 запроса? так или нет?
|
Цитата:
У меня есть две разные таблицы и я хочу записывать в них данные через этот скрипт. этой командой <?= print_r ($_POST);?> проверяю какие значения поступают с постом |
можете прислать весь html и php? то что вы сейчас прислали, сложно найти проблему. возможно даже проблема в другом
|
Цитата:
<script type="text/javascript" src="../reports/functions/jquery-1.2.6.pack.js"></script> <form action='test.php' method='post'> <table border='1' cellspacing='1' cellpadding='6' width='100%' id="table_container"> <tr> <td> Первая таблица </td> </tr> </table> <input type="button" value="Добавить поле" id="add" onclick="return add_new_image('#table_container');"> <script type="text/javascript"> var total = 0; function add_new_image(a){ total++; $('<tr>') .attr('id','tr_image_'+total) .css({lineHeight:'0px'}) .append ( $('<td>') .attr('id','td_title_'+total) .css({width:'5%'}) .append( $('<input type="text"/>') .css({width:'100%'}) .attr('id','1'+total) .attr('name','a1[]') ) ) .append( $('<td>') .attr('id','td_ name_'+total) .css({width:'50%'}) .append( $('<input type="text"/>') .css({width:'100%'}) .attr('id','5'+total) .attr('name','a2[]') ) ) .append( $('<td>') .attr('id','td_ name_'+total) .css({width:'35%'}) .append( $('<input type="text"/>') .css({width:'100%'}) .attr('id','5'+total) .attr('name','a3[]') ) ) .append( $('<td>') .attr('id','td_ name_'+total) .css({width:'10%'}) .append( $('<input type="text" />') .css({width:'100%'}) .attr('id','5'+total) .attr('name','a4[]') ) ) .appendTo(a); } $(document).ready(function() { add_new_image('#table_container'); }); </script> <input type="button" value="Добавить поле 2" id="add" onclick="return add_new_image('#table_container2');"> <table border='1' cellspacing='1' cellpadding='6' width='100%' id="table_container2"> <tr> <td> Вторая таблица </td> </tr> </table> <br> <script type="text/javascript"> var totalb = 0; function add_new_image(b){ totalb++; $('<tr>') .attr('id','tr_image_'+totalb) .css({lineHeight:'0px'}) .append ( $('<td>') .attr('id','td_title_'+totalb) .css({width:'5%'}) .append( $('<input type="text"/>') .css({width:'100%'}) .attr('id','1'+totalb) .attr('name','b1[]') ) ) .append( $('<td>') .attr('id','td_ name_'+totalb) .css({width:'50%'}) .append( $('<input type="text"/>') .css({width:'100%'}) .attr('id','5'+totalb) .attr('name','b2[]') ) ) .append( $('<td>') .attr('id','td_ name_'+totalb) .css({width:'35%'}) .append( $('<input type="text"/>') .css({width:'100%'}) .attr('id','5'+totalb) .attr('name','b3[]') ) ) .append( $('<td>') .attr('id','td_ name_'+totalb) .css({width:'10%'}) .append( $('<input type="text" />') .css({width:'100%'}) .attr('id','5'+totalb) .attr('name','b4[]') ) ) .appendTo(b); } $(document).ready(function() { add_new_image('#table_container2'); }); </script> <input type='submit' value='Сдать' name='Сдать'> </form> <pre> <?php print_r ($_POST);?> </pre> В результате выводится вот так: Array ( [b1] => Array ( [0] => 1 [1] => 5 ) [b2] => Array ( [0] => 2 [1] => 6 ) [b3] => Array ( [0] => 3 [1] => 7 ) [b4] => Array ( [0] => 4 [1] => 8 ) [Сдать] => Сдать ) А мне нужно чтобы выводилось так: Array ( [a1] => Array ( [0] => 1 ) [a2] => Array ( [0] => 2 ) [a3] => Array ( [0] => 3 [ ) [a4] => Array ( [0] => 4 ) [Сдать] => Сдать ) Array ( [b1] => Array ( [0] => 5 ) [b2] => Array ( [0] => 6 ) [b3] => Array ( [0] => 7 ) [b4] => Array ( [0] => 8 ) [Сдать] => Сдать ) В базу я уже сам запихаю с PHP и Mysql неплохо работаю, а вот со скриптами только начинаю.... |
ну во-первых:
id="add" я такую запись видел 2 раза. а 2 id'шника под одним именем быть не могут ну и второе. где идет ошибка... это сама функция function add_new_image(b){ сначала вы ее определяйте.. а потом еще одна функция с таким же именем.. т.е. код со старым скриптом стирайте и присваивайте новый скрипт.. т.е. переопределяете функцию можете сделать 2ве функции, но с разными именами |
Цитата:
<script type="text/javascript" src="../reports/functions/jquery-1.2.6.pack.js"></script> <form action='test.php' method='post'> <table border='1' cellspacing='1' cellpadding='6' width='100%' id="table_container"> <tr> <td> Первая таблица </td> </tr> </table> <input type="button" value="Добавить поле" id="add" onclick="return add_new_image('#table_container');"> <script type="text/javascript"> var total = 0; function add_new_image(a){ total++; $('<tr>') .attr('id','tr_image_'+total) .css({lineHeight:'0px'}) .append ( $('<td>') .attr('id','td_title_'+total) .css({width:'5%'}) .append( $('<input type="text"/>') .css({width:'100%'}) .attr('id','14'+total) .attr('name','a1[]') ) ) .append( $('<td>') .attr('id','td_ name_'+total) .css({width:'50%'}) .append( $('<input type="text"/>') .css({width:'100%'}) .attr('id','54'+total) .attr('name','a2[]') ) ) .append( $('<td>') .attr('id','td_ name_'+total) .css({width:'35%'}) .append( $('<input type="text"/>') .css({width:'100%'}) .attr('id','54'+total) .attr('name','a3[]') ) ) .append( $('<td>') .attr('id','td_ name_'+total) .css({width:'10%'}) .append( $('<input type="text" />') .css({width:'100%'}) .attr('id','54'+total) .attr('name','a4[]') ) ) .appendTo(a); } $(document).ready(function() { add_new_image('#table_container'); }); </script> <input type="button" value="Добавить поле 2" id="add2" onclick="return add_new_image('#table_container2');"> <table border='1' cellspacing='1' cellpadding='6' width='100%' id="table_container2"> <tr> <td> Вторая таблица </td> </tr> </table> <br> <script type="text/javascript"> var tot = 1000; function add_new_imageb(b){ tot++; $('<tr>') .attr('id','tr_image_'+tot) .css({lineHeight:'0px'}) .append ( $('<td>') .attr('id','td_title_'+tot) .css({width:'5%'}) .append( $('<input type="text"/>') .css({width:'100%'}) .attr('id','11'+tot) .attr('name','b1[]') ) ) .append( $('<td>') .attr('id','td_ name_'+tot) .css({width:'50%'}) .append( $('<input type="text"/>') .css({width:'100%'}) .attr('id','52'+tot) .attr('name','b2[]') ) ) .append( $('<td>') .attr('id','td_ name_'+tot) .css({width:'35%'}) .append( $('<input type="text"/>') .css({width:'100%'}) .attr('id','52'+tot) .attr('name','b3[]') ) ) .append( $('<td>') .attr('id','td_ name_'+tot) .css({width:'10%'}) .append( $('<input type="text" />') .css({width:'100%'}) .attr('id','52'+tot) .attr('name','b4[]') ) ) .appendTo(b); } $(document).ready(function() { add_new_imageb('#table_container2'); }); </script> <input type='submit' value='Сдать' name='Сдать'> </form> <pre> <?php print_r ($_POST);?> </pre> |
Часовой пояс GMT +3, время: 04:42. |