...

View Full Version : Syntax issue with hidden value from url



JCCDevel
04-29-2008, 02:50 PM
Hi All,

I have been trying to help a friend out(for real! She is a designer and I'm a developer but not very familiar with Javascript)

The situation: she is coming in from another page and is passing a value called "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 to a secure bank site. One of the things she needs to send is "chargetotal". She is attempting to do this by taking the value from the url, put it into a hidden form variable and then post it. If she hard codes the value it all works - but it doesn't work with the hidden value so clearly the syntax is all wrong. Here is the page:



<!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[i].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[i]+'<br>');
document.forms.form1.FeeCalcTotalDecimal.value = '+g[i]+' ;
</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>

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!

BarrMan
04-29-2008, 03:05 PM
First of all, the script tags should be inside of the head tags (at least the first script tag).
Secondly, The following statement would write +g[i]+:

document.forms.form1.FeeCalcTotalDecimal.value = '+g[i]+' ;
You should remove the single quotes from it.

Kor
04-29-2008, 03:54 PM
It guess you want something like that:


<!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>
<script type='text/javascript'>
/*<![CDATA[*/
onload=function(){
var qString = unescape(top.location.search.substring(1));
var qName=qString.split('&')[1].split('=')[0];
var qValue=qString.split('&')[1].split('=')[1];
document.forms['form1']['chargetotal'].value=qValue;
document.getElementById('tot').firstChild.nodeValue='Your total fee is $' +qValue;
}
/*]]>*/
</script>
</head>
<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">
<div id="tot">&nbsp;</div>
<form name="form1" method="post" action="https://secure.bANK.net/lpcentral/servlet/lppay">

<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" />
</form>
</td>
<td width="331"> </td>
</tr>
</table>
<div align="center"><font size="2" face="Geneva, Arial,
Helvetica, sans-serif">


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

JCCDevel
04-29-2008, 07:43 PM
Thank you both for your suggestions. I will have her try these out. I truly apprecuate the time you took to help!

Julie:cool:



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum