function stringCleanUp(msg)
{
//var msg = “project/reports/dispatcher_report.php?name=john&&sdate=2011-06-06&edate=2011-07-06”;
//this loops throught the string
//replacest he following:
//< charater with <
for(i = 0; i < msg.length; i++)
{
msg = msg.replace("<", "<");
}
//> charater with >
for(i = 0; i < msg.length; i++)
{
msg = msg.replace(">", ">");
}
//> charater with &
for(i = 0; i < msg.length; i++)
{
msg = msg.replace("&", "&");
}
return msg;
}
I think that you should encode the value parts separately, and then combine them all together afterwards.
Having said that though, can you put together a sample test page that demonstrates the problem that you are experiencing? Because I am unable to currently experience the problem you’re facing when using the code you posted in the first post, and using window.open to open a window with that newurl, or when assigning the newurl to the as the current location.
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<script>
var test="john";
var fdate=2011-06-06;
var tdate=2011-07-06;
var str1= '?name=' ;
var str2=test;
var str3= '&sdate=';
var str4=fdate;
var str5= '&edate=' ;
var str6=tdate;
var url="project/reports/dispatcher_report.php";
var newurl=url+str1+str2+str3+str4+str5+str6;
window.open(newurl);
</script>
</body>
</html>
If the URL is being displayed on the page then & is proper, since & needs to be encoded to form a valid HTML document. What is the problem caused by that conversion taking place?