Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Changing a form value programatically before submit 1

Status
Not open for further replies.

CMcC

Programmer
Feb 5, 2002
196
US
Hello.
I have a form where the user will enter an amount, where the field that they are entering it in is a variable that will be passed to another URL.
It is a number field (Currency). I would like to be able to add (.50 cent) onto the value of this field before the form is submitted. The field in question is
[red] "pg_total_amount".[/red]

This does not change what the user entered. Instead I get an error

"Must be numeric value and greater than zero : pg_total_amount. "





This is what I have so far:
Code:
<form method='post' action= '[URL unfurl="true"]https://swp.paymentsgateway.net/default.aspx'>[/URL]  <div align="center" onfocus="MM_validateForm('pg_billto_postal_name_company','','R');return document.MM_returnValue">
    <table width="574" border="0" align="center" cellspacing="0" bordercolor="#996600">
            
     
      <tr>
        <td align="right" width="260"><p align="right"><b>Dealer Name<font color="#ff0000" face="Arial, Helvetica"> *</font></b> </p></td>
        <td width="310"><font face="Arial, Helvetica">
              
          <input name="pg_billto_postal_name_company" id="pg_billto_postal_name_company" 
      size="35" />
        </font></td>
      </tr>
      <tr>
        <td align="right" width="260"><p><span class="style1"><b>Dealer Number</b></span><b><font color="#ff0000" face="Arial, Helvetica">*</font></b></p></td>
        <td width="310"><font face="Arial, Helvetica">
          <input name="pg_consumerorderid" id="pg_consumerorderid" 
      size="35" />
        </font></td>
      </tr>
      <tr>
        <td align="right" width="260"><p><span class="style1"><b>Payment Amoun</b></span><b>t  <font color="#ff0000" face="Arial, Helvetica"> *<span class="style3">(No comma) </span></font></b></p>
          <p><font face="Arial, Helvetica"><br />
            </font></p></td>
        [red]<td width="310"><font face="Arial, Helvetica">
          <input name="pg_total_amount" id ="pg_total_amount" 
      size="35" />[/red]
        </font></td>
      </tr>
      <tr>
        <td align="right" width="260"><p><span class="style1"><b>Batch Number</b></span><font face="Arial, Helvetica"><b><font 
      color="#ff0000" 
     >*</font></b></font></p></td>
        <td width="310"><font face="Arial, Helvetica">
              
          <input name="pg_merchant_data_3" id="pg_merchant_data_3" 
      size="35" />
        </font></td>
      </tr>
    </table>
   </div>
[red]
/*  THIS IS WHERE I TRY TO ALTER THE AMOUNT
<%
dim total_amount
total_amount = pg_total_amount + .50 
%>
[/red]



<table cellSpacing='0' cellPadding='0' border='0'><tr><td align='right' width='300'></td><td width='200' align='left' onfocus="MM_validateForm('pg_billto_postal_name_company','','R','pg_consumerorderid','','R','pg_total_amount','','R','pg_merchant_data_3','','R');return document.MM_returnValue">
<input type='hidden' name='pg_api_login_id' value='1PeYtqSMv5'/>

[red]
*/ THIS IS WHERE I WAS TRYING TO SEND OVER SUBMIT

<input type='hidden' name='pg_total_amount' value='<%=total_amount%>'/>
[/red]

<input type='hidden' name='pg_merchant_data_1' value='N/A'/>
<input type='hidden' name='pg_merchant_data_2' value='N/A'/>
<input type='hidden' name='pg_walletid' value='Dealer Work'/>
</td></tr><tr><td align='right' width='300'></td><td align='left' width='200'><input type='hidden' type='text' name='pg_return_url' value='[URL unfurl="true"]http://www.seminoletax.org/dev/dealer/dealerACHreturn.asp'/></td></tr><tr><td[/URL] align='right' width='300'></td><td align='left' width='200'><br></td></tr><tr><td align='right' width='300'></td><td align='left' width='200'><INPUT TYPE=SUBMIT value='Pay by eCheck Now'><br></td></tr></table></form>

So I guess my question is what is the appropriate syntax to change a form value before it is submitted?

THANKS!
 
If this is classic asp, you can't!

You need to use javascript. You can call it on the submit. Change your line <INPUT TYPE=SUBMIT value='Pay by eCheck Now'> to <INPUT TYPE=button value='Pay by eCheck Now' onClick="doSubmit()">

Your doSubmit() javascript function looks like this:
function doSubmit()
{
var totfld = getElementbyId('pg_total_amount');
totfld.value = parseFloat(totfld.value) + 0.5;
document.frmname.submit();
}

Oh, and stop using the crappy bloatware that Dreamweaver drops in when you do the simplest bit of validation!
 
Thank you Timfoster. Sometimes I get so bogged down in the details, I forget about stuff like this! I will definitely give it a try and post back my results. Thanks for responding so quickly.
Cmcc
 
Im not getting anything when I have this code:

Code:
<SCRIPT language="JavaScript">

<!--
function FormSubmit()
{
var totfld = getElementbyId('pg_total_amount');
totfld.value = parseFloat(totfld.value) + 0.5;
'pg_total_amount' = totfld.value
document.myform.submit();
}
</script>

with this as my form:

Code:
<form action= '[URL unfurl="true"]https://swp.paymentsgateway.net/default.aspx'[/URL] method='post'[red] name = "myForm" [/red] id="myForm">  
  <div align="center">
    <table width="574" border="0" align="center" cellspacing="0" bordercolor="#996600">
      <tr>
        <td align="right" width="260"><p><span class="style1"><b>Payment Amoun</b></span><b>t  <font color="#ff0000" face="Arial, Helvetica"> *<span class="style3">(No comma) </span></font></b></p>
          <p><font face="Arial, Helvetica"><br />
            </font></p></td>
        <td width="310"><font face="Arial, Helvetica">
         [red] <input name="pg_total_amount" id ="pg_total_amount" 
      size="35" />[/red]
        </font></td>
      </tr>
    </table>
    <p align="center">&nbsp;</p>
  </div>
<table cellSpacing='0' cellPadding='0' border='0'><tr><td align='right' width='300'></td><td width='200' align='left'>

</td></tr><tr><td align='right' width='300'></td><td align='left' width='200'><input type='hidden' type='text' name='pg_return_url' value='[URL unfurl="true"]http://www.seminoletax.org/dev/dealer/dealerACHreturn.asp'/></td></tr><tr><td[/URL] align='right' width='300'></td><td align='left' width='200'><br></td></tr><tr><td align='right' width='300'></td><td align='left' width='200'>[red]<input name="SUBMIT" type= BUTTON onclick='FormSubmit()' value='Pay by eCheck Now' />[/red]
  <br></td></tr></table>
</form>
 
Your javascript should be:

function FormSubmit()
{
var totfld = document.getElementbyId('pg_total_amount');
totfld.value = parseFloat(totfld.value) + 0.5;
document.myform.submit();
}

You needed the document object before getelement, and you had a surplus line which was trying to set a fixed string to a value (which you can't do). If you clicked the icon in the bottom left corner of your page, you'd see the errors.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top