最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Send span value to php script using post - Stack Overflow

programmeradmin1浏览0评论

I am trying to send data from form to the mail using php script. My problem is that i have span which is populated by javascript, but value of this span is not being sent using post function.

QtyA = 0;
PrcA = 15;
document.getElementById("product1").innerHTML = PrcA;

<form method="POST" action="form-to-email.php" name="ofrm">

    <table border="0" cellpadding="0" width="550" id="table1">
        <tr>
            <td width="250">Product1</td>
            <td align="center" width="100">
            <input type="text" name="qtyA" size="5" tabindex="5" onchange="calculate()"/></td>
            <td align="right" width="60"><span id="product1" name="PrcA"/></span></td>
            <td align="right" width="140">
            <input type="text" name="totalA" size="12" tabindex="99" onchange="calculate()"/></td>
        </tr>
</table>

i tried to replace span with

   <input type="text" name="PrcA" id="product1" size="5" tabindex="5" onchange="calculate()"/>

but input field is not populated by the javascript

php

.....

    $qtyA = $_POST['qtyA'];
    $PrcA = $_POST['PrcA'];
    ...
    $email_body = "$qtyA $PrcA".

variable $QtyA is sent, but $PrcA is not

thanks

I am trying to send data from form to the mail using php script. My problem is that i have span which is populated by javascript, but value of this span is not being sent using post function.

QtyA = 0;
PrcA = 15;
document.getElementById("product1").innerHTML = PrcA;

<form method="POST" action="form-to-email.php" name="ofrm">

    <table border="0" cellpadding="0" width="550" id="table1">
        <tr>
            <td width="250">Product1</td>
            <td align="center" width="100">
            <input type="text" name="qtyA" size="5" tabindex="5" onchange="calculate()"/></td>
            <td align="right" width="60"><span id="product1" name="PrcA"/></span></td>
            <td align="right" width="140">
            <input type="text" name="totalA" size="12" tabindex="99" onchange="calculate()"/></td>
        </tr>
</table>

i tried to replace span with

   <input type="text" name="PrcA" id="product1" size="5" tabindex="5" onchange="calculate()"/>

but input field is not populated by the javascript

php

.....

    $qtyA = $_POST['qtyA'];
    $PrcA = $_POST['PrcA'];
    ...
    $email_body = "$qtyA $PrcA".

variable $QtyA is sent, but $PrcA is not

thanks

Share Improve this question asked Sep 25, 2015 at 9:18 ivanzivanz 8253 gold badges12 silver badges32 bronze badges 3
  • You really shouldn't be using the <table> tag inside the form element... – Jordan Davis Commented Sep 25, 2015 at 9:29
  • thanks for the note, i assume i will try to change this to clean css in the future – ivanz Commented Sep 25, 2015 at 9:44
  • also, you can always call var_dump($_POST) if your doing testing. – Jordan Davis Commented Sep 25, 2015 at 9:55
Add a ment  | 

1 Answer 1

Reset to default 3

Put the value in an hidden field also.

Try this:

QtyA = 0;
PrcA = 15;
document.getElementById("product1").innerHTML = PrcA;
document.getElementById("PrcA").value = PrcA;

<form method="POST" action="form-to-email.php" name="ofrm">
<input type="hidden" value="" name="PrcA" id="PrcA" />

<table border="0" cellpadding="0" width="550" id="table1">
    <tr>
        <td width="250">Product1</td>
        <td align="center" width="100">
        <input type="text" name="qtyA" size="5" tabindex="5" onchange="calculate()"/></td>
        <td align="right" width="60"><span id="product1" name="PrcA"  /></span></td>
        <td align="right" width="140">
        <input type="text" name="totalA" size="12" tabindex="99" onchange="calculate()"/></td>
    </tr>

发布评论

评论列表(0)

  1. 暂无评论