Javascript 下拉列表脚本

Javascript 下拉列表脚本,javascript,jquery,html,Javascript,Jquery,Html,如何向这个javascript添加一个值数组,以便它在下拉列表中列出它们?我已经走了这么远,我真的被卡住了,我想这一定是对javascript的一个小小的补充 任何帮助都会很好 JAVASCRIPT var counter = 0; function addNew() { // Get the main Div in which all the other divs will be added var mainContainer = document.getElementBy

如何向这个javascript添加一个值数组,以便它在下拉列表中列出它们?我已经走了这么远,我真的被卡住了,我想这一定是对javascript的一个小小的补充

任何帮助都会很好

JAVASCRIPT
        var counter = 0;

function addNew() {

// Get the main Div in which all the other divs will be added
var mainContainer = document.getElementById('mainContainer');

// Create a new div for holding text and button input elements
var newDiv = document.createElement('div');

// Create a new text input

var newText = document.createElement('select');
newText.type = "select"; 


//for testing
newText.value = counter++;

// Create buttons for creating and removing inputs
var newAddButton = document.createElement('input');
newAddButton.type = "button";
newAddButton.value = " + ";

var newDelButton = document.createElement('input');
newDelButton.type = "button";
newDelButton.value = " - ";

// Append new text input to the newDiv
newDiv.appendChild(newText);

// Append new button inputs to the newDiv
newDiv.appendChild(newAddButton);
newDiv.appendChild(newDelButton);

// Append newDiv input to the mainContainer div
mainContainer.appendChild(newDiv);

// Add a handler to button for deleting the newDiv from the mainContainer
newAddButton.onclick = addNew;

newDelButton.onclick = function() {
        mainContainer.removeChild(newDiv);
};
}
HTML


t1
t2
t3
编辑PHP

 <?php
$name = $_POST['name'];
$email = $_POST['email'];
$number = $_POST['number'];
$Occasion = $_POST['Occasion'];
$Venues = $_POST['Venues'];
$date = $_POST['date'];
$guests = $_POST['guests'];
$custom = $_POST['custom'];
$from = $email; 
$to = 'ash.manterfield@btinternet.com'; 
$subject = 'New Menu Order';
$human = $_POST['human'];

$body = "From: $name\n Contact Number: $number\n E-Mail: $email\n Occasion: $Occasion\n    

Venues Looked At: $Venues\n Event Date: $date\n Number of Guests: $guests\n Custom    
Menu:\n $custom";

if ($_POST['submit']) {
if ($name != '' && $email != '') {
    if ($human == '4') {                 
        if (mail ($to, $subject, $body, $from)) { 
        echo '<h4>Your message has been sent!</h4>';
    } else { 
        echo '<h4>Something went wrong, go back and try again!</h4>'; 
    } 
} else if ($_POST['submit'] && $human != '4') {
    echo '<h4>You answered the anti-spam question incorrectly!</h4>';
}
} else {
    echo '<h4>You need to fill in all required fields!!</h4>';
}
}
 ?>


欢呼

从上一个选择框中获取值。在函数addNew()之后添加下面的代码{

这里是文档中创建的最后一个selectbox

并在以下内容之后添加新的
项目的html:

var newText = document.createElement('select');
newText.type = "select";

//Attribute Name use for form elements    
newText.setAttribute('name', 'text['+counter+']');

//Attribute id
newText.setAttribute('id', 'text_' + counter);

newText.innerHTML = items;

您可以看到如何从上一个选择框中获取值。在函数addNew()之后添加下面的代码。{

这里是文档中创建的最后一个selectbox

并在以下内容之后添加新的
项目的html:

var newText = document.createElement('select');
newText.type = "select";

//Attribute Name use for form elements    
newText.setAttribute('name', 'text['+counter+']');

//Attribute id
newText.setAttribute('id', 'text_' + counter);

newText.innerHTML = items;

您可以看到工作

什么值数组?我看不到javascript中的任何数组。简单文本如“1,2,3,4”,正如它在下拉列表中显示的那样单击
+
按钮时,您想添加或附加选项值吗?不添加新的下拉框,它们中的值都是相同的。什么值数组?我在javascript中看不到任何数组。简单文本如“1,2,3,4”,在下拉列表中显示您想在单击
+
按钮时添加或附加选项值吗?不添加新的下拉框,它们中的值都是相同的。为此干杯,只是想知道您是否知道新的下拉框的ID,这样我就可以将它们添加到我的php表单中谢谢,但您知道我可以怎么做吗把它整合到我的PHP中我将把PHP添加到上面你应该问另一个问题,想知道你是否知道新下拉框的ID是什么,所以我可以将它们添加到我的PHP表单中谢谢,但是你知道我如何将其整合到我的PHP中我将把PHP添加到上面你应该问另一个问题为了它
var newText = document.createElement('select');
newText.type = "select";

//Attribute Name use for form elements    
newText.setAttribute('name', 'text['+counter+']');

//Attribute id
newText.setAttribute('id', 'text_' + counter);

newText.innerHTML = items;