SitePoint Sponsor

User Tag List

Results 1 to 15 of 15
  1. #1
    SitePoint Zealot
    Join Date
    Dec 2010
    Posts
    107
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    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

  2. #2
    SitePoint Enthusiast
    Join Date
    Jul 2011
    Location
    South Africa
    Posts
    66
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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;



    </script>
    </head>
    <body>
    <div>
    <input type="button" onclick="alert(newurl);" />
    </div>
    </body>
    </html>
    result:
    project/reports/dispatcher_report.php?name=john&sdate=1999&edate=1998

  3. #3
    SitePoint Zealot
    Join Date
    Dec 2010
    Posts
    107
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hi

    Thanks for your reply

    But i am not using any encode function




    please help me out


    thanks

  4. #4
    SitePoint Enthusiast
    Join Date
    Jul 2011
    Location
    South Africa
    Posts
    66
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    have a look at this:


  5. #5
    SitePoint Enthusiast
    Join Date
    Jul 2011
    Location
    South Africa
    Posts
    66
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    try something like this:

    function stringCleanUp(msg)
    {
    //var msg = "project/reports/dispatcher_report.php?name=john&amp;&sdate=2011-06-06&amp;edate=2011-07-06";
    //this loops throught the string
    //replacest he following:

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

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

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

    return msg;
    }
    Last edited by ulricht609; Sep 7, 2011 at 23:53. Reason: misspelled entity

  6. #6
    SitePoint Zealot
    Join Date
    Dec 2010
    Posts
    107
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i have checked the html entities

    please help me out to remove this from url

    it is urgent







    Thanks

  7. #7
    SitePoint Zealot
    Join Date
    Dec 2010
    Posts
    107
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hi

    I tried the code but it is not working



    thanks

  8. #8
    SitePoint Zealot
    Join Date
    Dec 2010
    Posts
    107
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    please help me to resolve the issue

  9. #9
    SitePoint Enthusiast
    Join Date
    Jul 2011
    Location
    South Africa
    Posts
    66
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Exclamation

    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

  10. #10
    SitePoint Enthusiast
    Join Date
    Jul 2011
    Location
    South Africa
    Posts
    66
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    after browsing a bit i came across this:

    htmlspecialchars_decode()

    ------------------------

    from:
    -----------
    another:

    Last edited by ulricht609; Sep 8, 2011 at 05:23. Reason: adding more

  11. #11
    SitePoint Zealot
    Join Date
    Dec 2010
    Posts
    107
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi

    Dear paul wilkins


    please help me out to resolve this issue

  12. #12
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,701
    Mentioned
    101 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by samiuddin.adse View Post
    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.

    Code html4strict:
    <!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>
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  13. #13
    SitePoint Zealot
    Join Date
    Dec 2010
    Posts
    107
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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

  14. #14
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,701
    Mentioned
    101 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by samiuddin.adse View Post
    as said the code is correct but when I am this code with dhtmlxgrid then it is giving problem.
    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?
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  15. #15
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2006
    Location
    Augusta, Georgia, United States
    Posts
    4,147
    Mentioned
    16 Post(s)
    Tagged
    3 Thread(s)
    If the URL is being displayed on the page then &amp; is proper, since & needs to be encoded to form a valid HTML document. What is the problem caused by that conversion taking place?
    The only code I hate more than my own is everyone else's.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •