簡體   English   中英

將td數據傳遞給隱藏的輸入,然后使用PHP發布

[英]passing td data to a hidden input and then posting with PHP

我已經簡化了表格,但概念是相同的。

<form method=post action= somephp.php>
<table>
<tr><td><input name= first></tr>// These input are where people enter 
<tr><td><input name= second></tr>// numbers. They then click on
<tr><td><input name= third></tr>//calculate and the results appear
<tr><td><input name= fourth></tr>//in the below table
<td>Result one <input type = "hidden" name="somename" value=""></td>// 
<td>Result two <input type = "hidden" name="somename1  value=""></td>  
<button>Calculate</button>
<button type submit>save</button>
</form>

表格工作正常。 表格的數學運算是使用javascript執行的。 我按預期在結果1和2中得到結果的值。

現在解決我的問題單擊“計算”並得到結果后,單擊“保存”按鈕,希望它將所有輸入(包括隱藏的輸入)發布到PHP腳本中。

我在張貼隱藏的字段時遇到問題。

如果我在value屬性中放置一個圖形,但我一直想要整夜掙扎的是如何通過隱藏的字段將結果一個和兩個字段發布到我的PHP腳本中,那么它會起作用。

我一直在徒勞地嘗試從我的js腳本中獲取變量,以充當隱藏字段的值,但一直在PHP中獲取未定義的索引錯誤。 我認為可能是因為頁面已經加載。 我已經將保存結果一和結果二的值的變量附加到onChange事件等中,但是無法使其正常工作。

總結-如何將td內部HTML(結果1和結果2)傳遞給隱藏的輸入值,以發布到PHP腳本。 我願意接受其他解決方案

在此先感謝您的幫助。

<script>

var a = document.getElementByID('result one id').value;
var b = document.getElementByID('HIDDEN INPUT ID').value; 

我想要a = b

但正在掙扎

您可以考慮使用jquery設置隱藏字段的值。

<form method=post action= somephp.php>
<table>
    <tr><td><input name= "first" /></td></tr>
    <tr><td><input name= "second" /></td></tr>
    <tr><td><input name= "third" /></td></tr>
    <tr><td><input name= "fourth" /></td></tr>
    <td>Result one <input id="hidden1"  type = "text" name="somename" value=""/></td> 
    <td>Result two <input id="hidden2" type = "text" name="somename1"  value=""/></td>
<button id="calculate">Calculate</button>
<button id="submit" type="submit">save</button>
    </table>
</form>

和jQuery

    $(document).on('click', '#calculate', function(){ //you could perform your calculations here or define a separate function
      $('#hidden1').val('calculated value1');
      $('#hidden2').val('calculated value2');
      return false;
    });

小提琴

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM