Javascript-форум (https://javascript.ru/forum/)
-   Элементы интерфейса (https://javascript.ru/forum/dom-window/)
-   -   Данные вып. списка (https://javascript.ru/forum/dom-window/41122-dannye-vyp-spiska.html)

mgprog 01.09.2013 11:55

Данные вып. списка
 
Добрый день! Есть скрип скопированный с инета
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
<title>Добавление полей в форму</title> 
<meta http-equiv="Content-Type" content="text/html; charset=windows-1251" /> 


<script type="text/javascript" src="jquery-1.2.6.pack.js"></script> 
</head> 
<body> 

<script type="text/javascript"> 
var total = 0; 
function add_new_image(){ 
    total++; 
    $('<tr>') 
    .attr('id','tr_image_'+total) 
    .css({lineHeight:'20px'}) 
    .append ( 
        $('<td>') 
        .attr('id','td_title_'+total) 
        .css({paddingRight:'5px',width:'200px'}) 
        .append( 
            $('<input type="text" />') 
            .css({width:'200px'}) 
            .attr('id','input_title_'+total) 
            .attr('name','input_title_'+total) 
        ) 

    ) 

    .append ( 
        $('<td>') 
        .css({width:'60px'}) 
        .append ( 
            $('<span id="progress_'+total+'" class="padding5px"><a  href="#" onclick="$(\'#tr_image_'+total+'\').remove();" class="ico_delete"><img src="delete.png" alt="del" border="0"></a></span>') 
        ) 
    ) 
    .appendTo('#table_container'); 

} 
$(document).ready(function() { 
    add_new_image(); 
}); 
</script> 

<form action="" method="post"> 
    <table id="table_container"> 
        <tr> 
            <td width="100px" colspan="2"><strong>Название</strong></td> 

        </tr> 
    </table> 
        <br/> 
    <input type="button" value="Добавить поле" id="add" onclick="return add_new_image();"> 
    <input type="submit" value="Отправить"> 

</form> 

</body> 
</html> 
<?php 
$n = count($_POST); 
$key = array_keys($_POST); 
for($i=0; $i < $n; $i++) 
{ 
    echo $_POST[$key[$i]]."<br>"; 
} 
?>

В скрипте несколько полей типа text, при таком раскладе
$n = count($_POST);

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

mgprog 01.09.2013 12:19

Цитата:

Сообщение от mgprog (Сообщение 270310)
Добрый день! Есть скрип скопированный с инета
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
<title>Добавление полей в форму</title> 
<meta http-equiv="Content-Type" content="text/html; charset=windows-1251" /> 


<script type="text/javascript" src="jquery-1.2.6.pack.js"></script> 
</head> 
<body> 

<script type="text/javascript"> 
var total = 0; 
function add_new_image(){ 
    total++; 
    $('<tr>') 
    .attr('id','tr_image_'+total) 
    .css({lineHeight:'20px'}) 
    .append ( 
        $('<td>') 
        .attr('id','td_title_'+total) 
        .css({paddingRight:'5px',width:'200px'}) 
        .append( 
            $('<input type="text" />') 
            .css({width:'200px'}) 
            .attr('id','input_title_'+total) 
            .attr('name','input_title_'+total) 
        ) 

    ) 

    .append ( 
        $('<td>') 
        .css({width:'60px'}) 
        .append ( 
            $('<span id="progress_'+total+'" class="padding5px"><a  href="#" onclick="$(\'#tr_image_'+total+'\').remove();" class="ico_delete"><img src="delete.png" alt="del" border="0"></a></span>') 
        ) 
    ) 
    .appendTo('#table_container'); 

} 
$(document).ready(function() { 
    add_new_image(); 
}); 
</script> 

<form action="" method="post"> 
    <table id="table_container"> 
        <tr> 
            <td width="100px" colspan="2"><strong>Название</strong></td> 

        </tr> 
    </table> 
        <br/> 
    <input type="button" value="Добавить поле" id="add" onclick="return add_new_image();"> 
    <input type="submit" value="Отправить"> 

</form> 

</body> 
</html> 
<?php 
$n = count($_POST); 
$key = array_keys($_POST); 
for($i=0; $i < $n; $i++) 
{ 
    echo $_POST[$key[$i]]."<br>"; 
} 
?>

В скрипте несколько полей типа text, при таком раскладе
$n = count($_POST);

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

Вместо
Цитата:

Сообщение от mgprog
  $('<input type="text" />')

конечно же
Цитата:

$('<select size="1"><option value="value1">Item1</option><option value="value2">Item2</option></select>')


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