/    Sign up×
Community /Pin to ProfileBookmark

Results with & Dont Show Up

Hi everyone. I accidentally posted this in the wrong forum, so here it is.

I have this code that I modified from [url]http://javascript.internet.com/forms/confirm-order-thanks.html[/url] which allows me to take the results that have been checked on one page and confirms those results on another page (a demo of what I mean can be found at: [url]http://javascript.internet.com/forms/confirm-order.html)[/url].

Here is my version of the code (confirmation.php):

[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”>
<link rel=”stylesheet” type=”text/css” href=”_styles.css”>
<head>

<SCRIPT LANGUAGE=”JavaScript”>

<!– Begin
function decodeString() {
valNum = new Array();
valData = new Array();
var string, length, dataCount, orderData;
string = “” + unescape(location.search);
string = string.substring(1,string.length);
length = location.search.length;
orderData = “”;
dataCount = 1;
for (var c = 0; c < string.length; c++)
if (string.charAt(c).indexOf(“&”) != -1) dataCount++;

orderData = “<table border=0 width=85%>”;
orderData += “<tr bgcolor=”#FFFFFF”><td><b>Type:</b></td><td><b>Name:</b></td><td><b>City:</b></td><td><b>State:</b></td><td><b>Zip:</b></td><td><b>Contact:</b></td></tr>”;

for (var i = 0; i < dataCount; i++)
{
valNum[i] = string.substring(0,string.indexOf(“=”));
string = string.substring(string.indexOf(“=”)+1,string.length);
if (i == dataCount-1) valData[i] = string;
else valData[i] = string.substring(0,string.indexOf(“&”));
vpipe = valData[i].indexOf(“¦”);
slashzero = valData[i].indexOf(“Ø”);
doubleS = valData[i].indexOf(“§”);
doubledot = valData[i].indexOf(“¨”);
plusminus = valData[i].indexOf(“±”);
lftdubarrow = valData[i].indexOf(“«”);
rghtdubarrow = valData[i].indexOf(“»”);
rsType = string.substring(0,slashzero);
rsName = string.substring(slashzero+1,doubleS);
rsCity = string.substring(doubleS+1,doubledot);
rsState = string.substring(doubledot+1,plusminus);
rsZip = string.substring(plusminus+1,lftdubarrow);
rsContact = string.substring(lftdubarrow+1,rghtdubarrow);

string = string.substring(vpipe+1,string.length);

rsName = rsName.replace(/+/g, ” “);
rsCity = rsCity.replace(/+/g, ” “);
rsState = rsState.replace(/+/g, ” “);
rsZip = rsZip.replace(/+/g, ” “);
rsContact = rsContact.replace(/+/g, ” “);

if (i % 2)
{
orderData += “<tr bgcolor=”#FFFFFF”>”;
}
else
{
orderData += “<tr bgcolor=”#E9ECEF”>”
}
orderData += “<input type=hidden name=item” + (i+1) + “dsc value='” + rsType + “‘>”;
orderData += “<input type=hidden name=item” + (i+1) + “dsc value='” + rsName + “‘>”;
orderData += “<input type=hidden name=item” + (i+1) + “dsc value='” + rsCity + “‘>”;
orderData += “<input type=hidden name=item” + (i+1) + “dsc value='” + rsState + “‘>”;
orderData += “<input type=hidden name=item” + (i+1) + “dsc value='” + rsZip + “‘>”;
orderData += “<input type=hidden name=item” + (i+1) + “dsc value='” + rsContact + “‘>”;
orderData += “<td>” + rsType + “</td>”;
orderData += “<td>” + rsName + “</td>”;
orderData += “<td>” + rsCity + “</td>”;
orderData += “<td>” + rsState + “</td>”;
orderData += “<td>” + rsZip + “</td>”;
orderData += “<td>” + rsContact + “</td>”;
orderData += “</tr>”;
}

orderData += “<tr bgcolor=”#FFFFFF”>”;
orderData += “<td colspan=6 align=center><a href=’javascript:history.go(-1)’>Go Back</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href=”index.html”> Home</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href=’javascript:printWindow()’>Print This Page</a></td>”;
orderData += “</tr>”;
orderData += “</table>”;
document.write(orderData);
}

// End –>
</script>

<script>
function printWindow(){
bV = parseInt(navigator.appVersion)
if (bV >= 4) window.print()
}

</script>

</head>
<meta http-equiv=”Content-Type” content=”text/html; charset=iso-8859-1″ />
<title>Untitled Document</title>

<body>

<center>
<script language=”JavaScript”>
<!– Begin
decodeString();
// End –>
</script>
</center>
</form>

</body>
</html>[/CODE]

For the most part, it is working perfectly. There is only one problem with it… any result that has an & in it will not show on this confirmation page. I also tried changing the method on my results page from GET to POST, but that made my confirmation.php page not work at all.

I have been trying to figure out and research this issue for hours, but no luck. I am hoping someone will provide me with the miracle fix here :p . Any help is greatly appreciated and thanks in advance.

to post a comment
JavaScript

5 Comments(s)

Copy linkTweet thisAlerts:
@james64authorFeb 11.2008 — Alright, well I figured out the offending code that is not allowing my confirmation page to show results with &'s in them are these 2 lines:

line 19:

if (string.charAt(c).indexOf("&") != -1) dataCount++;

line 29:

else valData[i] = string.substring(0,string.indexOf("&"));



I have tried changing the &'s in these lines of code to something else (^), but that doesn't seem to work unfortunately...



Also, I noticed that when my confirmation page tries to output a result with an & in it, not only will it not show up, but it will also create an additional blank table row.



If anyone could help me out with this dilemma, I would greatly appreciate it! Thank you.
Copy linkTweet thisAlerts:
@cgishackFeb 12.2008 — You need to escape your quotes here..
<i>
</i>....&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;a href=[B]"index.html"[/B]&gt;


should be
<i>
</i>....&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;a href="index.html"&gt;

I would also look at used CSS instead of all the &nbsp; codes.

Drew
Copy linkTweet thisAlerts:
@james64authorFeb 12.2008 — Hi cgishack,

Thanks for the response. I actually changed that part of the code and instead of just having a ton of &nbsp;'s, I just made a table with 1 row and three columns, which works out perfectly.

That part is not the issue though. My problem has to do with the idea that my confirmation page is not showing any results with &'s in them. Again, I figured out that it has to do with

if (string.charAt(c).indexOf("&") != -1) dataCount++;

and

else valData[i] = string.substring(0,string.indexOf("&"));



since fiddeling with the &'s in those two lines of code changes my results around. When I replace the & from these lines, either one of two things happen: either (1) none of the results with an & appears or (2) only the first result with an & appears and nothing else appears after that.



Any other ideas?
Copy linkTweet thisAlerts:
@cgishackFeb 12.2008 — can you replace the & on the previous page with something like ++

then replace them back on the confirmation page?
Copy linkTweet thisAlerts:
@james64authorFeb 12.2008 — Well... there always is the option of replacing every '&' with 'and' in the database. That would fix everything (as I tested it with modifying the GET options in the URL), but I would rather not do that as this database will allow people to insert their own records. And since some businesses use & in their name, it would be great if I could just get my confirmation page to recognize them and output the results.

Is there any alternative to modifying the code so that the confirmation page will recognize &'s?
×

Success!

Help @james64 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 6.2,
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: @meenaratha,
tipped: article
amount: 1000 SATS,

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

tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,
)...