Issue with setting hidden value from url

J

JCCDevel

Hi All,

I'm not too proficient in Javascript but am trying to help a friend
out. Bascially, the page we are having trouble with is loaded with a
numerical value in the url string. Example:

http://www.webpage.com/v4/payment_pg.php?FeeCalcTotalDecimal =49.50

I then parse the string to get the total. I then want to assign the
value to a hidden form value
(document.form1.FeeCalcTotalDecimal.value) The hidden value is to be
used to post to a bank's website.

I'm sure this is just a syntax issue, but I'm stumped. Keep getting
"document.form1.FeeCalcTotalDecimal.value is null or not an object."

<CODE>

<script language="JavaScript">

function parseGetVars() {
var getVars = new Array();
var qString = unescape(top.location.search.substring(1));
var pairs = qString.split(/\&/);
for (var i in pairs) {
var nameVal = pairs.split(/\=/);
getVars[nameVal[0]] = nameVal[1];
}
return getVars;
}
</script>

<script>
var g = parseGetVars();
for (var i in g)
document.writeln('Your total fee is $' +g+'<br>');
document.form1.FeeCalcTotalDecimal.value = '+g+' ; THIS ISN'T
WORKING!!


</script>
<br />
</font> </div>
<table width="715" height="52" border="0">
<tr>
<td align="center" width="374" height="48"> <form
name="form1" method="post" action="https://secure.linkpt.net/lpcentral/
servlet/lppay">
<input type="hidden" name="txntype" value="sale">
<input type="hidden" name="storename" value="1001184858">
<INPUT type="hidden" name="chargetotal"
value="FeeCalcTotalDecimal">
<input type="hidden" name="suppressTitle" value="true">
<input name="Submit" type="submit" id="Submit" value="Submit">
</td>
<td width="331">
</div>
</form></td>
</tr>
</table>

</CODE>

Thanks in advance for your help!

JCC
 
T

Thomas 'PointedEars' Lahn

JCCDevel said:
I'm not too proficient in Javascript but am trying to help a friend
out.

FOAF? Yeah, sure ;-)
[...]
I then parse the string to get the total. I then want to assign the
value to a hidden form value
(document.form1.FeeCalcTotalDecimal.value) The hidden value is to be
used to post to a bank's website.

I'm sure this is just a syntax issue, but I'm stumped. Keep getting
"document.form1.FeeCalcTotalDecimal.value is null or not an object."

The script is located before the control in the markup; the control does
not exist at that point. Besides, your markup is not Valid[1] and you are
using proprietary syntax. Use instead, after the control was parsed:

document.forms["form1"].elements["FeeCalcTotalDecimal"].value

[1] http://validator.w3.org/


HTH

PointedEars
 
E

Evertjan.

JCCDevel wrote on 17 apr 2008 in comp.lang.javascript:
document.form1.FeeCalcTotalDecimal.value = '+g+' ; THIS ISN'T
WORKING!!


reason1:

The form form1 is not yet declared and so not yet part of the DOM.

reason2:

<INPUT type="hidden" name="chargetotal"
value="FeeCalcTotalDecimal">

Should be something like:

<INPUT type="hidden" name="FeeCalcTotalDecimal"
value="">


=============================

Why use outmoded
<script language="JavaScript">
and
<script>
where
<script type='text/javascript'>
is the standard?

Why split the script in two?

Change 1
document.form1.
to
document.forms.form1.

<table width="715" height="52" border="0">
use css styles instead!

In the end,
better fill the hidden input with serverside code.
ASP example:

<INPUT type="hidden" name="FeeCalcTotalDecimal"
value = '<% = serversideValue %>'>
 
J

JCCDevel

JCCDevel said:
I'm not too proficient in Javascript but am trying to help a friend
out.

FOAF?  Yeah, sure ;-)
[...]
I then parse the string to get the total. I then want to assign the
value to a hidden form value
(document.form1.FeeCalcTotalDecimal.value) The hidden value is to be
used to post to a bank's website.
I'm sure this is just a syntax issue, but I'm stumped.  Keep getting
"document.form1.FeeCalcTotalDecimal.value is null or not an object."

The script is located before the control in the markup; the control does
not exist at that point.  Besides, your markup is not Valid[1] and you are
using proprietary syntax.  Use instead, after the control was parsed:

  document.forms["form1"].elements["FeeCalcTotalDecimal"].value

[1]http://validator.w3.org/

HTH

PointedEars
--
    realism:    HTML 4.01 Strict
    evangelism: XHTML 1.0 Strict
    madness:    XHTML 1.1 as application/xhtml+xml
                                                    -- Bjoern Hoehrmann

Thank you both for your suggestions. I have asked my friend(and yes
Thomas, it is for a friend - she is strictly a designer and hasn't had
to do this type of thing before) to plug this into her page. I'm used
to using server side code and her page is just stand-alone. I truly
appreciate your help!
 
J

JCCDevel

FOAF?  Yeah, sure ;-)
[...]
I then parse the string to get the total. I then want to assign the
value to ahiddenform value
(document.form1.FeeCalcTotalDecimal.value) Thehiddenvalue is to be
used to post to a bank's website.
I'm sure this is just a syntax issue, but I'm stumped.  Keep getting
"document.form1.FeeCalcTotalDecimal.value is null or not an object."
The script is located before the control in the markup; the control does
not exist at that point.  Besides, your markup is not Valid[1] and youare
using proprietary syntax.  Use instead, after the control was parsed:
  document.forms["form1"].elements["FeeCalcTotalDecimal"].value

PointedEars
--
    realism:    HTML 4.01 Strict
    evangelism: XHTML 1.0 Strict
    madness:    XHTML 1.1 as application/xhtml+xml
                                                    -- Bjoern Hoehrmann

Thank you both for your suggestions.  I have asked my friend(and yes
Thomas, it is for a friend - she is strictly a designer and hasn't had
to do this type of thing before) to plug this into her page.  I'm used
to using server side code and her page is just stand-alone.  I truly
appreciate your help!- Hide quoted text -

- Show quoted text -

OK, she is still having trouble and I'm not able help her. Still not
getting the value to pass. Just to remind you.... she is coming in
from another page and is passing the chargetotal in the url(agree it's
probably not the best way but she's not in a position to re-write the
whole thing). When on this page, she needs to post some information
tot he bank. One of the things she needs to send is "chargetotal".
She is attempting to do this by taking the value from the url, putting
it into a hidden form variable and then posting it. If she hard codes
the value it all works, doesn't work with the hidden value so clearly
the syntax is all wrong. Here are her changes:

<CODE>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://
www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1" />
<title>Payment Page</title>
</head>

<script type='text/javascript'>
function parseGetVars() {
var getVars = new Array();
var qString = unescape(top.location.search.substring(1));
var pairs = qString.split(/\&/);
for (var i in pairs) {
var nameVal = pairs.split(/\=/);
getVars[nameVal[0]] = nameVal[1];
}
return getVars;
}
</script>



<body>

<table width="507" border="0" align="center" bgcolor="#FFFFFF">
<tr>
<td height="31"><p align="center"><font color="#660000" size="6"
face="Bookman Old Style">Payment
Options TEST</font></p></td>
</tr>
<tr>
<td height="358" valign="top" background="images/badge.gif"><div
align="center"><font size="2" face="Geneva, Arial, Helvetica, sans-
serif"><br />


<br />
</font> </div>
<table width="715" height="52" border="0">
<tr>
<td align="center" width="374" height="48">
<form name="form1" method="post" action="https://secure.bANK.net/
lpcentral/servlet/lppay">
<script type='text/javascript'>
var g = parseGetVars();
for (var i in g)
document.writeln('Your total fee is $' +g+'<br>');
document.forms.form1.FeeCalcTotalDecimal.value = '+g+' ;
</script>
<input type="hidden" name="txntype" value="sale">
<input type="hidden" name="storename" value="1001184858">
<INPUT type="hidden" name="chargetotal" value="">
<input type="hidden" name="suppressTitle" value="true">
<input name="Submit" type="submit" id="Submit" value="Submit">
</td>
<td width="331">
</div>
</form></td>
</tr>
</table>
<div align="center"><font size="2" face="Geneva, Arial,
Helvetica, sans-serif">

</font></div></td>
</tr>
</table>
</body>
</html>



</CODE>

Realize that this pretty basic stuff for anybody with good knowledge
of Javascript - but that is not us! So, you have our eternal thanks
for your assistance!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,996
Messages
2,570,238
Members
46,826
Latest member
robinsontor

Latest Threads

Top