Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UrlDecode value on html textbox on submit

I have a very simple form with three fields that I need to submit to an mvc action. The form must be application/x-www-form-urlencoded. however, one of the fields is populated by users copying and pasting an already urlencoded value. I would like to decode that value prior to submitting the form. this seems really simple but I keep running into proplems with my javascript.

Here is the code:

   <html>
    <head>
<script>
function decodeURI()
{
decodeURIComponent(document.createprofile.URI.value);
}
</script>
    <title>Test Create</title>
    </head>
    <body>
    <center>
    <h1> Spoof Profile Calls </h1>
    <hr>
    <div style="border: 1px solid black; width: 300px;">
    <b>Create</b>
    <form method="post" action="https://test.test-lab.com/Profile/Create/" name="createprofile">
    <input type="hidden" name="ReturnURL" value="self.close()">
    UserName: <input type="text" name="UserName"><br />
    Client: <input type="text" name="Client"><br />
    URI: <input type="text" name="URI" onblur="decodeURI();"><br />
    <input type="submit" formenctype="application/x-www-form-urlencoded" value="Go To - Create"><br />
    </form>
    </div>
    </body>
    </html>

The URI field is the one that needs url decoded prior to submission because it gets reencoded and thus corrupted. I could ask the users to un-encode these values themselves but they are not terribly sophisticated users and it will likely not happen.

Thank you in advance!

UPDATED WITH FAILING CODE

like image 788
RockyMountainHigh Avatar asked Feb 04 '26 22:02

RockyMountainHigh


1 Answers

Replace the line

URI: <input type="text" name="URI" onblur="decodeURI();"><br />

by

URI: <input type="text" name="URI" onchange="decodeURI(this);"><br />

And do something like

function decodeURI(elm) {
    elm.value = 'foo ' + elm.value + ' bar';
    return false;
}
like image 189
showi Avatar answered Feb 06 '26 13:02

showi