/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] Passing chargetotal value

I need to take a value generated by a javascript and pass it through a hidden input in an html form.

My LinkPoint merchant states that I need to use the following to pass the total:

<input type=”hidden” name=”chargetotal” value=””>

I need to have the value generated by the script inserted into the value tag so that information can be passed on. Below is the Form and script I would like to use. I would like to stick with the chargetotal value because it’s my linkpoint merhcant example – not sure what to do.

[CENTER]:eek: 😮 😮 😮 :eek:[/CENTER]

[CODE]
<LINK REL=”stylesheet” TYPE=”text/css” HREF=”/styleseet.css”>
<script language=”JavaScript” type=”text/javascript”>
<!–

function CalculateTotal(frm) {
var order_total = 0

// Run through all the form fields
for (var i=0; i < frm.elements.length; ++i) {

// Get the current field
form_field = frm.elements[i]

// Get the field’s name
form_name = form_field.name

// Is it a “product” field?
if (form_name.substring(0,4) == “PROD”) {

// If so, extract the price from the name
item_price = parseFloat(form_name.substring(form_name.lastIndexOf(“_”) + 1))

// Get the quantity
item_quantity = parseInt(form_field.value)

// Update the order total
if (item_quantity >= 0) {
order_total += item_quantity * item_price
}
}
}

// Display the total rounded to two decimal places
frm.TOTAL.value = round_decimals(order_total, 2)
frm.CHARGETOTAL.value = frm.TOTAL.value
}

function round_decimals(original_number, decimals) {
var result1 = original_number * Math.pow(10, decimals)
var result2 = Math.round(result1)
var result3 = result2 / Math.pow(10, decimals)
return pad_with_zeros(result3, decimals)
}

function pad_with_zeros(rounded_value, decimal_places) {

// Convert the number to a string
var value_string = rounded_value.toString()

// Locate the decimal point
var decimal_location = value_string.indexOf(“.”)

// Is there a decimal point?
if (decimal_location == -1) {

// If no, then all decimal places will be padded with 0s
decimal_part_length = 0

// If decimal_places is greater than zero, tack on a decimal point
value_string += decimal_places > 0 ? “.” : “”
}
else {

// If yes, then only the extra decimal places will be padded with 0s
decimal_part_length = value_string.length – decimal_location – 1
}

// Calculate the number of decimal places that need to be padded with 0s
var pad_total = decimal_places – decimal_part_length

if (pad_total > 0) {

// Pad the string with 0s
for (var counter = 1; counter <= pad_total; counter++)
value_string += “0”
}
return value_string
}

//–>
</script>

<A NAME=”top”></A>

<!–START THE HEADER–>

<TABLE WIDTH=100% CELLPADDING=0 CELLSPACING=0 BORDER=0 BGCOLOR=#000000>
<TR>
<TD BGOLOR=#000000>&nbsp;</TD>
</TR></TABLE>

<!–END THE HEADER–>

<!–START THE CONTENT–>
<DIV STYLE=”margin-left: 5px; font-family: Arial, Verdana, Helvetica, Geneva, ‘MS Sans Serif'”>

<CENTER><TABLE WIDTH=610 CELLSPACING=0 CELLPADDING=0><TR><TD><IMG SRC=”/Graphics/spacer.gif” HEIGHT=1 WIDTH=610>
<P>

<P>

<FORM>
<TABLE BORDER =3>

<TD COLSPAN=3><B> RSVP FORM</B></TD>

<TR>
<TD width=”88″ ALIGN=”CENTER”>Enter qty:</FONT></TD>
<TD width=”140″ ALIGN=”CENTER”><B>Membership Status</TD>
<TD width=”101″ ALIGN=”CENTER”><B>Price (each)</B></TD>
</TR>
<TR>
<TD ALIGN=”CENTER”><INPUT TYPE=TEXT NAME=”PROD_SP_125.00″ SIZE=3 MAXLENGTH=3 onChange=”CalculateTotal(this.form)”></TD><TD>Alumni</TD><TD ALIGN=”RIGHT”>125</TD>
</TR>
<TR><TD ALIGN=”CENTER”><INPUT TYPE=TEXT NAME=”PROD_SPMG_150.00″ SIZE=3 MAXLENGTH=3 onChange=”CalculateTotal(this.form)”></TD><TD>Non-Alumni</TD><TD ALIGN=”RIGHT”>150</TD>
</TR>

<TR><TD><BR></TD><TD>TOTAL</TD><TD ALIGN=”RIGHT”><INPUT TYPE=TEXT NAME=TOTAL SIZE=10 onFocus=”this.form.elements[0].focus()”></TD>

</TABLE>
<P>

<INPUT TYPE=RESET VALUE=”CLEAR FORM”>

</FORM>

<H3>There are no refunds if not requested within 5 days of the event you are paying for. </H3>

<FORM action=”https://www.linkpointcentral.com/lpc/servlet/lppay”method=”post”>

<INPUT type=”hidden” name=”mode” value=”PayPlus”>

<INPUT type=”hidden” name=”storename” value=”1234567″>

<INPUT TYPE=”hidden” name=”chargetotal” value=”0.00″>

<INPUT type=”submit” value=”Click To Donate”>

</Form>[/CODE]

This is by far the most mind boggling thing my head has endured thus far. Detailed help is much appreciated as my knowledge of j-script is weak.

to post a comment
PHP

7 Comments(s)

Copy linkTweet thisAlerts:
@jcavemanDec 19.2010 — The function that generates your total is called "CalculateTotal". Any time your total changes, you want to update the hidden field value with this new total, so I would add a little bit of code to the bottom of your "CalculateTotal" function, like this:

[CODE]function CalculateTotal(frm) {
var order_total = 0;

// Run through all the form fields
for (var i=0; i < frm.elements.length; ++i) {

// Get the current field
form_field = frm.elements[i];

// Get the field's name
form_name = form_field.name;

// Is it a "product" field?
if (form_name.substring(0,4) == "PROD") {

// If so, extract the price from the name
item_price = parseFloat(form_name.substring(form_name.lastIndexOf("_") + 1));

// Get the quantity
item_quantity = parseInt(form_field.value);

// Update the order total
if (item_quantity >= 0) {
order_total += item_quantity * item_price;
}
}
}

// Display the total rounded to two decimal places
frm.TOTAL.value = round_decimals(order_total, 2);
frm.CHARGETOTAL.value = frm.TOTAL.value;

/***** Here's the code I've added *****/
document.getElementsByName("chargetotal").value = round_decimals(order_total, 2);

}
[/CODE]

I indented the code to make it easier to read, and I added semicolons to the end of the lines; this is a JavaScript requirement and will cause your code to break in most browsers.

I hope this helps.
Copy linkTweet thisAlerts:
@Benjamin78authorDec 19.2010 — Hey jcaveman,

That didn't work for me. I'm still getting the same error message...pretty much it's still not passing. Any other suggestions?
Copy linkTweet thisAlerts:
@jcavemanDec 19.2010 — This code should work:

[CODE]
<LINK REL="stylesheet" TYPE="text/css" HREF="/styleseet.css">
</head>
<body>
<script language="JavaScript" type="text/javascript">
<!--

function CalculateTotal(frm) {
var order_total = 0;

// Run through all the form fields
for (var i=0; i < frm.elements.length; ++i) {

// Get the current field
form_field = frm.elements[i];

// Get the field's name
form_name = form_field.name;

// Is it a "product" field?
if (form_name.substring(0,4) == "PROD") {

// If so, extract the price from the name
item_price = parseFloat(form_name.substring(form_name.lastIndexOf("_") + 1));

// Get the quantity
item_quantity = parseInt(form_field.value);

// Update the order total
if (item_quantity >= 0) {
order_total += item_quantity * item_price;
}
}
}

// Display the total rounded to two decimal places
frm.TOTAL.value = round_decimals(order_total, 2);
frm.chargetotal.value = frm.TOTAL.value;
}

function round_decimals(original_number, decimals) {
var result1 = original_number * Math.pow(10, decimals)
var result2 = Math.round(result1)
var result3 = result2 / Math.pow(10, decimals)
return pad_with_zeros(result3, decimals)
}

function pad_with_zeros(rounded_value, decimal_places) {

// Convert the number to a string
var value_string = rounded_value.toString();

// Locate the decimal point
var decimal_location = value_string.indexOf(".");

// Is there a decimal point?
if (decimal_location == -1) {

// If no, then all decimal places will be padded with 0s
decimal_part_length = 0;

// If decimal_places is greater than zero, tack on a decimal point
value_string += (decimal_places > 0) ? "." : "";

}else{

// If yes, then only the extra decimal places will be padded with 0s
decimal_part_length = value_string.length - decimal_location - 1;

}

// Calculate the number of decimal places that need to be padded with 0s
var pad_total = decimal_places - decimal_part_length;

if (pad_total > 0) {

// Pad the string with 0s
for (var counter = 1; counter <= pad_total; counter++){
value_string += "0";
}

return value_string;

}

}


//-->
</script>




<A NAME="top"></A>

<!--START THE HEADER-->

<TABLE WIDTH=100&#37; CELLPADDING=0 CELLSPACING=0 BORDER=0 BGCOLOR=#000000>
<TR>
<TD BGOLOR=#000000>&nbsp;</TD>
</TR></TABLE>

<!--END THE HEADER-->

<!--START THE CONTENT-->
<DIV STYLE="margin-left: 5px; font-family: Arial, Verdana, Helvetica, Geneva, 'MS Sans Serif'">

<CENTER><TABLE WIDTH=610 CELLSPACING=0 CELLPADDING=0><TR><TD><IMG SRC="/Graphics/spacer.gif" HEIGHT=1 WIDTH=610>
<P>

<P>

<FORM action="https://www.linkpointcentral.com/lpc/servlet/lppay" method="post">
<TABLE BORDER =3>

<TD COLSPAN=3><B> RSVP FORM</B></TD>

<TR>
<TD width="88" ALIGN="CENTER">Enter qty:</FONT></TD>
<TD width="140" ALIGN="CENTER"><B>Membership Status</TD>
<TD width="101" ALIGN="CENTER"><B>Price (each)</B></TD>
</TR>
<TR>
<TD ALIGN="CENTER"><INPUT TYPE=TEXT NAME="PROD_SP_125.00" SIZE=3 MAXLENGTH=3 onChange="CalculateTotal(this.form)"></TD><TD>Alumni</TD><TD ALIGN="RIGHT">125</TD>
</TR>
<TR><TD ALIGN="CENTER"><INPUT TYPE=TEXT NAME="PROD_SPMG_150.00" SIZE=3 MAXLENGTH=3 onChange="CalculateTotal(this.form)"></TD><TD>Non-Alumni</TD><TD ALIGN="RIGHT">150</TD>
</TR>



<TR><TD><BR></TD><TD>TOTAL</TD><TD ALIGN="RIGHT"><INPUT TYPE="TEXT" NAME="TOTAL" SIZE=10 onFocus="this.form.elements[0].focus()"></TD>

</TABLE>
<P>

<INPUT TYPE=RESET VALUE="CLEAR FORM">

</FORM>


<H3>There are no refunds if not requested within 5 days of the event you are paying for. </H3>




<INPUT type="hidden" name="mode" value="PayPlus">

<INPUT type="hidden" name="storename" value="1234567">

<INPUT TYPE="hidden" name="chargetotal" value="6.00">

<INPUT type="submit" value="Click To Donate">

</FORM>[/CODE]


Also, this is the entire page you're working on is it? This snippet doesn't have a doc type or the appropriate headings, etc. If you did this on purpose, no sweat. If you'd like me to wrap this code to make it a complete HTML document, let me know.
Copy linkTweet thisAlerts:
@Benjamin78authorDec 19.2010 — Hi Jcaveman...

You've been much help. I'm grateful, but it's still not working. [I]If I wasn't so close I would throw my computer through the wall.[/I]

So I actually copied/pasted your exact code and inserted my correct store number then I hit preview and when I clicked the button to submit I'm getting the following error message which by the way is the error message that I have been getting all along:

? ? :mad:


Form Processing Error

The following errors occurred while processing your request:

It is not possible to order from the store at this time.

Contact the merchant for further information (error 1002).

? ? :mad:

The store is fine because I used the just the forms info minus the tables and the j-script info and it went directly to the pay page...so something in the script is preventing it from going through.
Copy linkTweet thisAlerts:
@jcavemanDec 19.2010 — That is not a JavaScript error- that is a LinkPoint error. I Googled "LinkPoint error 1002" and this was the first result:

[URL="http://sgserror.com/faq_connect.php#1002"]

http://sgserror.com/faq_connect.php#1002[/URL]


Per that link:

"Error 1002 is due to either the wrong URL (http) address entered on the LinkPoint Connect settings or the URL address has additional arguments (question mark). LinkPoint Connect does not support dynamic URLs. You can access the settings for LinkPoint Connect by logging into LinkPoint Central.

Once you login you will click on Customization at the top.

Then click on "Configure your LinkPoint Connect."

Look for the field, "Order submission form URL," and verify you have the correct address for your order page.

If you have more than one page make sure you separate them with a space.

You have to make sure you upload (ftp) the file to your web site first before you try to test it.

The following example will not work with Connect because the query string at the end of the URL will always change.

http://www.yourdomain.com/order.asp?id=1002&product=cd&total=12.00

If your web site or shopping cart has a dynamic URL that changes like the example above you will need to program it so that it does not add the string. If you are not able to change the URL address then you might want to consider getting a secure server (SSL certificate) and using LinkPoint API."
Copy linkTweet thisAlerts:
@Benjamin78authorDec 19.2010 — Dear sir,

I speak to you with the upmost respect when I say that you are the SH*T!!!! I completely forgot that I had to do that. :o Completely. :o

FYI: After fixing my mistake...I tried both codes that you sent me. The first one did not work (see it below).
[CODE]
document.getElementsByName("CHARGETOTAL").value = round_decimals(order_total, 2);
[/CODE]


As I was getting the following error message: [I][COLOR="Red"]Total must be a number between 0.00 and 99999.99.[/COLOR][/I]

No sweat because the last one did work; although, I removed the 6.00 from the CHARGETOTAL and did clean up the HTML as I had certain things that was not closed off. Thank you for the adjustment made to the code in general.

Funny I looked up part of the error message and never got such a detail response. Blonde I tell ya blonde...no offense if you are.

Thank you a million times over once again. ? ?
Copy linkTweet thisAlerts:
@jcavemanDec 19.2010 — No sweat- glad you got it working!
×

Success!

Help @Benjamin78 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...