Creating url using javascript

Hi

all

I want to send the javascript variables to a url

for example

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;

the url should look like this

project/reports/dispatcher_report.php?name=john&sdate=2011-06-06&edate=2011-07-06

but the url is looking something like this

project/reports/dispatcher_report.php?name=john&&sdate=2011-06-06&edate=2011-07-06

please help me to resolve this issue

thanks
Samiuddin

i tested your code and it gave me the result you are looking, maybe you have some kind of encode feature/function


code used to test:

<html>
<head>
<title>Untitled Page</title>
<script type=“text/javascript”>

    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;

&lt;/script&gt;

</head>
<body>
<div>
<input type=“button” onclick=“alert(newurl);” />
</div>
</body>
</html>

result:

project/reports/dispatcher_report.php?name=john&sdate=1999&edate=1998

hi

Thanks for your reply

But i am not using any encode function

please help me out

thanks

have a look at this:

HTML Entities

try something like this:

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:

            //&lt; charater with &lt;
            for(i = 0; i &lt; msg.length; i++)
            {
                msg = msg.replace("&lt;", "&lt;");

            }
            //&gt; charater with &gt;
            for(i = 0; i &lt; msg.length; i++)
            {
                msg = msg.replace("&gt;", "&gt;");
           }

           //&gt; charater with &amp;
            for(i = 0; i &lt; msg.length; i++)
            {
                msg = msg.replace("&amp;", "&");
           }

            return msg;
        }

i have checked the html entities

please help me out to remove this from url

it is urgent

Thanks

hi

I tried the code but it is not working

thanks

please help me to resolve the issue

i took your example code and I did not receive the same error, so i can’t say what the actual error is, therefore i can’t make any more suggestions.

if you could elaborate a bit more, maybe posting the offending section of code.

If I can’t reproduce the error then technically it is not erroring :shifty:

after browsing a bit i came across this:

htmlspecialchars_decode()


from:

[SOLVED] &amp instead of &


another:

http://www.phing.info/trac/ticket/17

Hi

Dear paul wilkins

please help me out to resolve this issue

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>

Hi

Paul

thanks for your reply

as said the code is correct but when I am this code with dhtmlxgrid then it is giving problem.

regards
samiuddin

Ahh, that’s the first time we’ve heard about dhtmlxgrid from you on this thread.

Can you link us to an example page that experiences the problem?

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?