When a button is clicked on a form, I need to fill in hidden elements that will be posted. The script below should set the values for these hidden fields:
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<!-- setting all the hidden fields --->
<script type="text/javascript" >
function fnGetPara() {
document.getElementById('EPS_MERCHANT').value = bta_merchant;
document.getElementById('EPS_TXNTYPE').value = bta_txntype;
document.getElementById('EPS_REFERENCEDID').value = bta_referenceId;
document.getElementById('EPS_AMOUNT').value = bta_amount;
document.getElementById('EPS_TIMESTAMP').value = bta_timestamp;
document.getElementById('EPS_FINGERPRINT').value = bta_fingerprint;
document.getElementById('EPS_RESULTURL').value = bta_jumpback;
}
</script>
<!-- finish setting all the hidden fields --->
<form method="post" action="https://....." id="form1" runat="server">
<div class="docdisplay">
<!-- merchant -->
<input type="hidden" name="EPS_MERCHANT" id="EPS_MERCHANT" />
<!-- transaction -->
<input type="hidden" name="EPS_TXNTYPE" id="EPS_TXNTYPE" />
<!-- reference -->
<input type="hidden" name="EPS_REFERENCEDID" id="EPS_REFERENCEDID"/>
<!-- amount to be paid -->
<input type="hidden" name="EPS_AMOUNT" id="EPS_AMOUNT" />
<!-- Timestamp -->
<input type="hidden" name="EPS_TIMESTAMP" id="EPS_TIMESTAMP"/>
<!-- fingerprint -->
<input type="hidden" name="EPS_FINGERPRINT" id="EPS_FINGERPRINT" />
<!-- where we want to go after the payment -->
<input type="hidden" name="EPS_RESULTURL" id="EPS_RESULTURL" />
....
</div>
<div class="docbuttons">
<asp:Button ID="lblauth" runat="server" Text="Authorise payment" OnClick="lblauth_Click" />
</div>
Below is the method that handles the click event of the button and sets the values for the hidden fields:
protected void lblauth_Click(object sender, EventArgs e)
{
// get bank transaction data
bankTransAct.setTransactValues(orderId, invoiceNo, orderpaid, out bta_merchant, out bta_pw, out bta_txntype, out bta_amount, out bta_referenceId, out bta_timestamp, out bta_fingerprint);
Page.ClientScript.RegisterStartupScript(this.GetType(), "CallfnGetPara", "fnGetPara()", true);
}
The "bankTransAct" method retrieves values for these hidden fields.
I have tried different variations for the id values but the hidden fields are still not getting filled when I trace the page. However, manual filling of the hidden fields works fine.
Any feedback or suggestions would be appreciated as I'm unable to identify where the mistake lies?