传递所有行选择的选项值,这些值由用户输入的php确定

时间:2017-10-27 09:14:05

标签: javascript php sqlsrv

如果用户随机生成选定的选项值,我该如何传递? 如果我确定了值,如何获取每行的每个选定选项的值?

像这样的东西。

的Javascript

<script>
    function submitForm(action)
    {
        document.getElementById('columnarForm').action = action;
        document.getElementById('columnarForm').submit();
    }
</script>

PHP

 <form class="form-horizontal" action="" method="post" id="columnarForm">
      <!-- some html tag -->
<?php

if ($_SERVER['REQUEST_METHOD'] =='POST' && isset($_POST['addButton1'])) {
    $table = $_POST['selectTable'];
    if($table == 'company')
    {
        $num = $_POST['num'];
        for($j = 1; $j <= $num; $j++) {
            ?>
        <tr id="row1">
            <td align="right"><?php echo $j; ?></td>
            <td id="name_row1" width="2px">
                <input type="text" id="new_name" name="text<?php echo $j; ?>" value=""></td>
                <td id="country_row1">
                    <select class="selectField" onChange="" id="selectcom" name="selectcom<?php echo $j; ?>">
                        <option value="">-- Select Field --</option>
                        <option value="comp_id<?php echo $j; ?>">comp_id</option>
                        <option value="comp_name<?php echo $j; ?>">comp_name</option>
                    </select>
                </td>
                <td><input type="text" name="default" size="10"></td>
                <td id="data_row"><div id="new_text<?php echo $j;?>"></div></td>
                <td id="size_row"><div id="size_row<?php echo $j;?>"></div></td>
                <td>
                    <input type="button" value="Delete" class="delete btn btn-small btn-info" onclick="delete_row('row1')">
                </td>
            </tr>
            <?php
        }
    }
?>

<button type="submit" class="btn btn-primary noty" name="next" onclick="submitForm('import.php')">Create Template</button>

如何在下一页(import.php)提供变量? 对不起我的英语不完善

1 个答案:

答案 0 :(得分:0)

$('#noc').change(function(e) {
		$('.child').remove();
		id = $(this).val();
		for(var i=1; i<id; i++){
			var thisRow = $('.dd').last(".dd");	
			var newid = parseInt(thisRow.attr('divid'))+1;		
			newRow = thisRow.clone(true).insertAfter(thisRow).find('input').val('').end().
			find('.name').each(function(){
				$(this).attr('id', 'name-'+newid);
				$(this).attr('name','name-'+(newid));
				$(this).attr('placeholder','Name '+(newid));
			}).end().find('.drop').each(function(){
				$(this).attr('id', 'dd-'+newid);
				$(this).attr('name','dd-'+(newid));
			}).end();
			thisRow.next('.dd').attr("divid",newid).addClass("child");
		}
    });
div{    display: inline-table;}
<link rel="stylesheet" href="http://getbootstrap.com/dist/css/bootstrap.min.css" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script><section style="width:40%" align="center">
	<form>
        <div class="col-md-12"><input type="text" class="form-control" id="noc" /></div>
        
        <div class="dd" divid="1" align="center">
            <div class="col-md-6">Field Name</div>
            <div class="col-md-6">Column Name</div>
            <div class="col-md-6"><input type="text" placeholder="Name 1" class="name form-control" id="name-1" name="name-1" /></div>
            <div class="col-md-6">
                <select name="dd-1" id="dd-1" class="drop form-control">
                    <option>value 1</option>
                    <option>value 2</option>
                    <option>value 3</option>
                    <option>value 4</option>
                </select>
            </div>
        </div>
    </form>
</section>

检查此代码