2012-08-10 112 views
0

我有两个表单提交给一个目标页面。将两个表单内容提交到一个行动页面

<form name= "form1" id="form1" action="final.php"> 
<input type="box1" name="box1" value="" > 
</form> 

<form name ="form2" id="form2" action="final.php"> 
<table> 
<input type ="text" id="txt_1" name ="txt_1" value=""> 

... 


</table> 
</form> 

<input type= "button" name="mybutton" id="mybutton" onclick="somefunction();"> 

这里,

Form1中有一些satic内容

窗口2具有动态被JS所产生的表... 问题是...我想提交从这两种形式的值到同一页面final.php ...如何cud我这样做.....请避免jquery/ajax ... 简单的JavaScript欢迎...

提前致谢!


这是在窗口2生成动态表中的JS

<script type="text/javascript"> 

function viewsource() { 
alert(document.body.innerHTML); 
} 
</script> 
<script type="text/javascript"> 

function addRowToTable() 
{ 
    var tbl = document.getElementById('tblSample'); 
    var frm=document.form2; 
    if (!frm.ary) frm.ary=[frm.t1_1,frm.t1_2,frm.t1_3]; 
    var lastRow = tbl.rows.length; 
    // if there's no header row in the table, then iteration = lastRow + 1 
    var iteration = lastRow; 
    var row = tbl.insertRow(lastRow); 



    // numberd row 
    var cellLeft = row.insertCell(0); 
    var textNode = document.createTextNode(iteration); 
    cellLeft.appendChild(textNode); 

    // Item row 
    var cellRight1 = row.insertCell(1); 
    var el1 = document.createElement('input'); 
    frm.ary.push(el1); 
    el1.type = 'text'; 
    el1.value = ''; 
    el1.name = 't' + iteration + '_1'; 
    el1.id = 't' + iteration + '_1'; 
    el1.size = 13; 
    el1.onkeyup=Calc; 
    el1.onblur=Calc; 
    cellRight1.appendChild(el1); 

    // Price row 
    var cellRight2 = row.insertCell(2); 
     var el2 = document.createElement('input'); 
    frm.ary.push(el2); 
    el2.type = 'text'; 
    el2.value = ''; 
    el2.name = 't' + iteration + '_2'; 
    el2.id = 't' + iteration + '_2'; 
    el2.size = 10; 
    el2.onkeyup=Calc; 
    el2.onblur=Calc; 
    cellRight2.appendChild(el2); 

    // Price row 
    var cellRight3 = row.insertCell(3); 
    var el3 = document.createElement('input'); 
    frm.ary.push(el3); 
    el3.type = 'text'; 
    el3.value = '0'; 
    el3.name = 't' + iteration + '_3'; 
    el3.id = 't' + iteration + '_3'; 
    el3.size = 10; 
    cellRight3.appendChild(el3); 

    } 

    function removeRowFromTable() 
    { 
     var tbl = document.getElementById('tblSample'); 
     var lastRow = tbl.rows.length; 
    if (lastRow > 3) tbl.deleteRow(lastRow - 1); 
    } 

    function formReset() 
    { 
     document.getElementById("form2").reset(); 
    } 
    </script> 

    <script type="text/javascript"> 


    function Calc(){ 
    var frm=document.form2; 
    if (!frm.ary){ frm.ary=[frm.t1_1,frm.t1_2,frm.t1_3];} 
     for (var zxc0=0;zxc0<frm.ary.length;zxc0+=3) 
    { 
     var total =1; 
    if (frm.ary[zxc0].value.length>0&&!isNaN(frm.ary[zxc0].value)) 
    { 
    total =frm.ary[zxc0].value*1* frm.ary[zxc0+1].value; 
    } 
     frm.ary[zxc0+2].value =total; 

     } 
    var sum1 =0; 
    for (var zxd0=0;zxd0<frm.ary.length;zxd0+=3) 
    { 
     if (frm.ary[zxd0+2].value.length>0&&!isNaN(frm.ary[zxd0+2].value)) 
    { 
    sum1 +=parseInt(frm.ary[zxd0+2].value); 
     } 
     } 
     frm.sum.value = sum1; 
    } 


    </script> 


    <form action="final.php" method="post" name="form2" id="form2"> 
    <imput type ="text" name ="temp" id="temp" > 
    <table border="2" border-color="#000000" border-type="solid" id="tblSample"    
    align="center" font-size="20"> 
    <tr> 
    <th> 
    <input type="button" value="Add " onclick="addRowToTable();"></th><th> 
    <input type="button" value="Remove " onclick="removeRowFromTable();" /></th> 
    <th> <input type="button" value="Reset" onclick="formReset();"> 
    </th> 

    </tr><br> 

     <tr id="cloneid" > 
     <td> 
     1. 
     </td> 
     <td> 
    <input type="text" name="t1_1" id="t1_1" size="16" value="0" onkeyup="Calc();" 
     onblur="Calc();"> 
     </td> 
    <td> 
     <input type="text" name="t1_2" id="t1_2" size="16" value="0" onkeyup="Calc();"  
    onblur="Calc();"> 
    </td> 
    <td> 
     <input type="text" name="t1_3" id="t1_3" value= "0" size="16"> 
     </td> 

    </tr> 
     </table> 
    <table border="2" border-color="#000000" align="center"> 
<tr> 
    <td colspan="3" align="center"> 
    Sum: <input type="text" name="sum" id="sum"> 
    </td> 

    </tr> 
    </table> 
    </form> 

<input type="button" name = "mybutton" id ="mybutton" value="set" 
    onclick="somefunction();"> 

    } 

Form1中提到包括jQuery的沿难熬夫妇的文本框datetimepickers是一样的...

+8

合并形式2到形式1 – perilbrain 2012-08-10 11:16:03

+1

尼基尔,简单地删除:'<形式名称= “窗口2” ID = “窗口2” 行动= “final.php”>'和仅提交'form1'。或者你还有其他障碍? – Stano 2012-08-10 11:19:10

+0

合并它们并使用div作为动态内容.. – thecodejack 2012-08-10 11:22:59

回答

0
您可以使用Java脚本

function button1click() { 
    yourForm.action = "Final.php"; 
    yourForm.submit(); 
} 
在HTML

Ñ

<form action='' method='post'> 
    .. 
</form> 
+0

另一种形式呢? – Nikhil 2012-08-10 12:04:42

+0

你可以用同样的方法添加其他表单和它的JS函数。无论何时提交表格,该表格都会在该页面上发布 – 2012-08-11 06:08:47

相关问题