Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 11 of 11
  1. #1
    New to the CF scene
    Join Date
    Aug 2010
    Posts
    8
    Thanks
    1
    Thanked 0 Times in 0 Posts

    decode input into url

    hi, i was wondering if anyone could help me with decoding an input box value and passing that into the url. its been super frurstrating trying to do this. thank you in advance!

    basically i wrote a function that decodes a url. for example if i enter t05:34:23-79-79.003z.444z, i want it to stay like that when it goes into the url. if you use internet explorer, entering that input becomes... t05%3A34%3A23-79-79.003z.444z. on google chrome, it stays as t05:34:23-79-79.003z.444z but i need this to work on internet explorer.

    [<html>
    <head>
    <script type="text/javascript">
    function decode() {
    var obj = document.getElementById("workorder");
    alert(obj); //is it normal that this alert just returns 'object'? am i calling the form wrong somehow?
    var encoded = obj.value;
    obj.value = decodeURIComponent(encoded.replace(/\+/g, " "));

    }
    </script>
    </head>
    <body>
    <div id="workorder" style="display: block">
    <form name = "workorder" action="http://localhost/Lights/WorkOrder.jsp" onsubmit="return validate_form(this)" method="get"><b>WorkOrder:</b>
    <br> Id Required: <input type="hidden" name="method"
    value="getWorkOrders">
    <input type="text" name="lightId" size="30">
    <input type="submit" onclick="decode()" value="Go"> <br>
    </form>
    </div>
    </body>
    </html>]

    thank you advance!

  • #2
    Regular Coder low tech's Avatar
    Join Date
    Dec 2009
    Posts
    849
    Thanks
    172
    Thanked 92 Times in 92 Posts
    Hi


    alert(obj); //is it normal that this alert just returns 'object'? am i calling the form wrong somehow?
    Yes and Yes.


    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">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Untitled Document</title>
    </head>
    <script type="text/javascript">
    function decodeIt() {
    
    	var uri=document.workorder.lightId.value;
    		alert(uri);	
    	var encodeuri = encodeURIComponent(uri);
    		alert(encodeuri);
    	var decodeuri = decodeURIComponent(encodeuri);
    		alert(decodeuri);
    		
    	location.href= decodeuri;
    }
    </script>
    </head>
    <body>
    <div id="workorder" style="display: block">
    <form name = "workorder" action="http://localhost/Lights/WorkOrder.jsp" onsubmit="return validate_form(this)" method="get"><b>WorkOrder:</b>
    <br> Id Required: <input type="hidden" name="method"
    value="getWorkOrders"> 
    <input type="text" name="lightId" size="30">
    <input type="submit" onclick="decodeIt()" value="Go"> <br>
    </form>
    </div>
    </body>
    </html>
    ps the function is NOT intended to be a complete answer to your problem ---- althouh it might help in some way

  • #3
    New to the CF scene
    Join Date
    Aug 2010
    Posts
    8
    Thanks
    1
    Thanked 0 Times in 0 Posts
    oh thanks for telling me how to call it correctly = )

    is there a way to put the decoded into the url?

  • #4
    Regular Coder low tech's Avatar
    Join Date
    Dec 2009
    Posts
    849
    Thanks
    172
    Thanked 92 Times in 92 Posts
    Hi

    Have you tried the script?

    The location.href part puts the decoded into the url. Type something into the input -- it will be passed to the url.

    The alerts are there to help you work out your problem.

    I'm not a pro coder and as I said this is NOT intended to be a COMPLETE answer to your problem.

    good luck.

  • #5
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,028
    Thanks
    75
    Thanked 4,325 Times in 4,291 Posts
    You *WANT* the ENCODED in the URL. If the query string is not encoded, then the servers may not handle it correctly!

    What you really need is to be able to *decode* the URL.

    And your JSP page *SHOULD* be doing that automatically, for you.

    The standard JSP methods to get the value of a single form field *will* decode it properly.

    If there is a problem here, it is surely in your JSP code.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #6
    New to the CF scene
    Join Date
    Aug 2010
    Posts
    8
    Thanks
    1
    Thanked 0 Times in 0 Posts
    i tried running the script, but the encoded version still gets passed into the url. passing in t05:34:23-79-79.003z.444z into the input box still results in http://localhost/Lights/WorkOrder.js...9-79.003z.444z in internet explorer.

  • #7
    New to the CF scene
    Join Date
    Aug 2010
    Posts
    8
    Thanks
    1
    Thanked 0 Times in 0 Posts
    cause i know the exact format of the input, and its going to be like t05:34:23-79-79.003z.444z. its on a local server and it needs to have the : in it

  • #8
    Regular Coder low tech's Avatar
    Join Date
    Dec 2009
    Posts
    849
    Thanks
    172
    Thanked 92 Times in 92 Posts
    Hi

    but the encoded version still gets passed into the url. passing in t05:34:23-79-79.003z.444z into the input box still results in http://localhost/Lights/WorkOrder.js...9-79.003z.444z in internet explorer.
    Yep, thats exactly what I got in IE and FF which is why I said it's NOT a COMPLETE answer to your request but it may help you see what's going on.

    See post at #5.

    LT
    Last edited by low tech; 08-09-2010 at 02:44 AM.

  • #9
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,028
    Thanks
    75
    Thanked 4,325 Times in 4,291 Posts
    Quote Originally Posted by starmandell View Post
    i tried running the script, but the encoded version still gets passed into the url. passing in t05:34:23-79-79.003z.444z into the input box still results in http://localhost/Lights/WorkOrder.js...9-79.003z.444z in internet explorer.
    And I say again: You *WANT* the URL to *APPEAR* like that! IF IT DOES NOT then the URL will *NOT* submit properly to your server!!!

    Your JSP page COULD AND SHOULD properly handle that encoding!

    In particular, the JSP page should do
    Code:
    String lightid = request.getParameter("lightId");
    and the String that results *WILL* be decoded correctly.

    The HTTP specification *REQUIRES* the correct encoding of query string values! If the query string *appears* unencoded in the browser's address bar, that may just be appearance. In point of fact, the query string as it will be sent to the server could and should be encoded.

    Basically, any character that could be mistaken to be part of the standard HTTP "meta" information should be encoded. That means / : ? & % space + and more. There is not ANY gurantee that a non-encoded URL is going to work and/or work properly.

    ANYWAY...If your JSP code isn't handling that encoding properly, then your JSP code has a bug in it. Period.
    Last edited by Old Pedant; 08-09-2010 at 03:37 AM.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #10
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,028
    Thanks
    75
    Thanked 4,325 Times in 4,291 Posts
    In short, you should *NOT* have any decode() function in that code and you should *NOT* be attempting to undo what the browser is CORRECTLY doing.

    Your <form> should consist ONLY of
    Code:
    <form name = "workorder" action="http://localhost/Lights/WorkOrder.jsp" onsubmit="return validate_form(this)" method="get">
    <input type="hidden" name="method" value="getWorkOrders" /> 
    <b>WorkOrder:</b>
    <br> Id Required:  <input type="text" name="lightId" size="30" />
    <input type="submit" value="Go"/>
    <br>
    </form>
    You don't show what your validate_form() function is doing, but it clearly should not be trying to encode anything.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #11
    New to the CF scene
    Join Date
    Aug 2010
    Posts
    8
    Thanks
    1
    Thanked 0 Times in 0 Posts
    oh okay. ill keep that in mind. thank you!


  •  

    Tags for this Thread

    Posting Permissions

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