/    Sign up×
Community /Pin to ProfileBookmark

Inserting a value into a hidden input html form

This is my first Post – If I’m not in the right place, I apologize, and appreciate being re-directed. Thanks in advance.

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

The example given to me by the Gateway is:

<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 the Gateway’s example – not sure what to do.

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

/* This script is Copyright (c) Paul McFedries and
Logophilia Limited ([url]http://www.mcfedries.com/)[/url].
Permission is granted to use this script as long as
this Copyright notice remains in place.*
/

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)

}

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>
<CENTER>
<TABLE WIDTH=620 CELLPADDING=0 CELLSPACING=0 BORDER=0>
<TR>

<TD WIDTH=100% VALIGN=TOP ALIGN=RIGHT BGCOLOR=#000000>
<TABLE>
<TR>
<TD>

<SCRIPT LANGUAGE=”JavaScript”>
<!–
function CheckSelection() {
var selection = document.frmLinkList.FileName.options[document.frmLinkList.FileName.selectedIndex].value
if (selection != “None”) {
location.href = selection;
return false;
}
else
return false;
}

function QuickClick(list) {
var selection = list.options[list.selectedIndex].value
if (selection != “None”)
location.href = selection
}

//–>
</SCRIPT>

<FORM METHOD=POST ACTION=”/cgi-win/archive-selector.exe” NAME=”frmLinkList” onClick=”return CheckSelection()”>
<IMG SRC=”/graphics/spacer.gif” HEIGHT=5 WIDTH=1><BR>

<!–<FONT FACE=”Arial, Verdana, Helvetica, MS Sans Serif” COLOR=#FFFFFF SIZE=-1><B> then </B></FONT><INPUT TYPE=SUBMIT VALUE=”Go!”>–>
</FORM>
</TD>
</TR>
</TABLE>
</TD>
</TR>
</TABLE>
</CENTER>
</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><BR>

<FONT FACE=”Arial, Verdana, Helvetica, MS Sans Serif” COLOR=#000088 SIZE=+2 CLASS=”TitleText”>
<B>REMS Training, Inc.</B>
</FONT>
<P>

<HR>
<P>

<FORM>

<H3>COURSES OF INSTRUCTION</H3>

<TABLE BORDER =3>

<TD COLSPAN=3><B>PLEASE ENTER A QUANTITY NUMBER THEN CLICK TOTAL</B></TD>

<TR><TD ALIGN=”CENTER”><B>Please <BR>
enter <BR>
quantity:</FONT></TD>
<TD ALIGN=”CENTER”><B>Description</TD><TD ALIGN=”CENTER”><B>Price<BR>
(each)</B></TD></TR>
<TR>
<TD ALIGN=”CENTER”><INPUT TYPE=TEXT NAME=”PROD_SP_425.00″ SIZE=3 MAXLENGTH=3 onChange=”CalculateTotal(this.form)”></TD><TD>NYS Bail Enforcement Agent (Bounty Hunter)</TD><TD ALIGN=”RIGHT”>$425.00</TD>
</TR>
<TR><TD ALIGN=”CENTER”><INPUT TYPE=TEXT NAME=”PROD_SPMG_425.00″ SIZE=3 MAXLENGTH=3 onChange=”CalculateTotal(this.form)”></TD><TD>NYS Private Investigator</TD><TD ALIGN=”RIGHT”>$425.00</TD>
</TR>
<TR><TD ALIGN=”CENTER”><INPUT TYPE=TEXT NAME=”PROD_SPCR_4.99″ SIZE=3 MAXLENGTH=3 onChange=”CalculateTotal(this.form)”></TD><TD>Spelt Cinnamon-Raisin Bread 24 oz</TD><TD ALIGN=”RIGHT”>$4.99</TD>
</TR>
<TR><TD ALIGN=”CENTER”><INPUT TYPE=TEXT NAME=”PROD_SW_3.99″ SIZE=3 MAXLENGTH=3 onChange=”CalculateTotal(this.form)”></TD><TD>Spelt White Bread* 18 oz</TD><TD ALIGN=”RIGHT”>$3.99</TD>
</TR>
<TR><TD ALIGN=”CENTER”><INPUT TYPE=TEXT NAME=”PROD_SWMG_3.99″ SIZE=3 MAXLENGTH=3 onChange=”CalculateTotal(this.form)”></TD><TD>Spelt White Multi-Grain Bread*
with Flax Seeds 18 oz</TD><TD ALIGN=”RIGHT”>$3.99</TD>
</TR>
<TR><TD ALIGN=”CENTER”><INPUT TYPE=TEXT NAME=”PROD_RY_4.99″ SIZE=3 MAXLENGTH=3 onChange=”CalculateTotal(this.form)”></TD><TD>Rye Bread (Wheat Free, not sliced) 24 oz</TD><TD ALIGN=”RIGHT”>$4.99</TD>
</TR>
<TR><TD ALIGN=”CENTER”><INPUT TYPE=TEXT NAME=”PROD_KT_4.99″ SIZE=3 MAXLENGTH=3 onChange=”CalculateTotal(this.form)”></TD><TD>Kamut<FONT SIZE=1 COLOR=#000000>&#174;</FONT> Bread 24 oz</TD><TD ALIGN=”RIGHT”>$4.99</TD>
</TR>
<TR><TD ALIGN=”CENTER”><INPUT TYPE=TEXT NAME=”PROD_KCR_4.50″ SIZE=3 MAXLENGTH=3 onChange=”CalculateTotal(this.form)”></TD><TD>Kamut Cinnamon-Raisin Bread 24 oz</TD><TD ALIGN=”RIGHT”>$4.50</TD>
</TR>
<TR><TD ALIGN=”CENTER”><INPUT TYPE=TEXT NAME=”PROD_KA_4.99″ SIZE=3 MAXLENGTH=3 onChange=”CalculateTotal(this.form)”></TD><TD>Kamut Almond-Raisin Bread* 24 oz</TD><TD ALIGN=”RIGHT”>$4.99</TD>
</TR>
<TR><TD ALIGN=”CENTER”><INPUT TYPE=TEXT NAME=”PROD_AG_2.99″ SIZE=3 MAXLENGTH=3 onChange=”CalculateTotal(this.form)”></TD><TD>Ancient Grains Bread 18 oz <FONT FACE=”Calamari” SIZE=4 COLOR=#008000>NEW!</FONT></TD><TD ALIGN=”RIGHT”>$2.99</TD>
<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>The Total Amount to be charged to your credit card appears above next to the word TOTAL. Click the Submit button to continue on to provide credit card information. There are no refunds if requested within 7 days of the class you are paying for</H3>

<FORM
action=”https://secure.linkpt.net/lpcentral/servlet/lppay
method=”post”>
<INPUT type=”hidden” name=”mode” value=”fullpay”>
<INPUT type=”hidden” name=”chargetotal” value=” “>
<INPUT type=”hidden” name=”storename”
value=”123456″>
<INPUT type=”submit” value=”Continue to secure payment
form”> </Form>

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@SpectreReturnsMay 20.2005 — Wrong forum. Send it over to the Javascript gurus.
Copy linkTweet thisAlerts:
@Natcon67May 20.2005 — I think you could try to add your hidden input field before the end of the </form> like this: [code=php]
<input type="hidden" name="chargetotal" value="">
</FORM>
[/code]


and add the second line here in the script tags
[code=php]
frm.TOTAL.value = round_decimals(order_total, 2)
frm.chargetotal.value = frm.TOTAL.value //add this line to the script
[/code]


** Make sure that you put it in the correct place**

this will populate the hidden value so that you can send it on with the form.
Copy linkTweet thisAlerts:
@Jerry_S_authorMay 21.2005 — Thank you - I will try what you suggest and let you know the results.

Thanks again.
×

Success!

Help @Jerry_S_ 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.7,
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,
)...