PHP发布JS for循环中生成的数组值

时间:2015-03-02 17:09:30

标签: javascript php

我正在使用此脚本生成一个稍后将出现在表单中的代码。 我有这个代码工作2页,但我不知道为什么它不能发布到下一页。

以下是我的代码:

   function add(){



var coun    = document.getElementById('count').value; 

if(coun==""){var count = 1;}
else{var count = (coun*1)+1;}


if(count>=1){
show('cont_del');   
}

var field       = "";
var table       = "";
var desc_arr    = "";
var itn_arr     = "";
var qty_arr     = "";
var cls_arr     = "";
var unp_arr     = "";
var tot_arr     = "";




for(var f=1;f<count;f++){

    desc_arr    = document.getElementById('desc'+f).value;
    itn_arr     = document.getElementById('itn'+f).value;
    qty_arr     = document.getElementById('qty'+f).value;
    <? if($_POST['type']=="o"){ ?>
    cls_arr     = document.getElementById('cls'+f).value;
    <? } ?>
    unp_arr     = document.getElementById('unp'+f).value;
    tot_arr     = document.getElementById('tot'+f).value;


    field = field+"<table class='style5'><tr bgcolor='#FFFFFF'>";
    field = field+"<td width='70'><b>"+f+"</b></td>\n";
<? if($_POST['type']!="s"){ ?>  
    field = field+"<td width='130'>";
    field = field+"<input name='itn[]' id='itn"+f+"' type='text' class='input' size='5' maxlength='11' value='"+itn_arr+"'>";
    field = field+"</td>\n";
<? } ?> 
    field = field+"<td width='200'>";
    field = field+"<input name='desc[]' id='desc"+f+"' type='text'
  class='input' size='30' value='"+desc_arr+"'>";
    field = field+"</td>\n";                            
    field = field+"<td width='70'>";
    field = field+"<input name='qty[]' id='qty"+f+"'
 onchange='totcalc("+f+");' type='text' class='input' size='3' 
value='"+qty_arr+"'>";
    field = field+"</td>\n";
<? if($_POST['type']=="o"){ ?>          
    field = field+"<td width='70'>";
    field = field+"<input name='cls[]' id='cls"+f+"' type='text'
 class='input' size='3' value='"+cls_arr+"'>";
    field = field+"</td>\n";
<? } ?>         
    field = field+"<td width='150'>";
    field = field+"<input name='unp[]' id='unp"+f+"' 
    onchange='totcalc("+f+");digit("+f+")' type='text' class='input' 
    size='10' value='"+unp_arr+"'>";
    field = field+"</td>\n";
    field = field+"<td width='150'>";
    field = field+"<input name='tot[]' id='tot"+f+"' type='text' 
    class='input' size='10' value='"+tot_arr+"'>";
    field = field+"</td>\n";
    field = field+"</tr></table>\n\n";

}


var table = "<table class='style5'><tr bgcolor='#FFFFFF'>";
    table = table+"<td width='70'><b>"+count+"</b></td>\n";
<? if($_POST['type']!="s"){ ?>      
    table = table+"<td width='130'>";
    table = table+"<input name='itn[]' id='itn"+count+"' type='text'
 class='input' size='5' maxlength='11'>";
    table = table+"</td>\n";
<? } ?>     
    table = table+"<td width='200'>";
    table = table+"<input name='desc[]' id='desc"+count+"' type='text'
 class='input' size='30'>";
    table = table+"</td>\n";
    table = table+"<td width='70'>";
    table = table+"<input name='qty[]' id='qty"+count+"' 
onchange='totcalc("+count+");' type='text' class='input' size='3'   
value='0'>";
    table = table+"</td>\n";
<? if($_POST['type']=="o"){ ?>  
    table = table+"<td width='70'>";
    table = table+"<input name='cls[]' id='cls"+count+"' type='text'     
class='input' size='3'";
    table = table+"</td>\n";
<? } ?>         
    table = table+"<td width='150'>";
    table = table+"<input name='unp[]' id='unp"+count+"' 
onchange='totcalc("+count+"); digit("+count+")' type='text' 
class='input' size='10' value='0.00'>";
    table = table+"</td>\n";
    table = table+"<td width='150'>";
    table = table+"<input name='tot[]' id='tot"+count+"'  
    type='text' class='input' size='10' value='0.00'>";
    table = table+"</td>\n";
    table = table+"</tr></table>\n\n";



    document.getElementById("add").innerHTML = field + table;

    document.getElementById("count").value = (count*1);
}

稍后所有内容都会发布到div id =&#39;添加&#39;嵌套表中的容器。

当我发布表单时,没有发布变量。

0 个答案:

没有答案