Valor de UrlDecode en el cuadro de texto html al enviar

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.

Aquí está el código:

   <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.

Gracias de antemano!

UPDATED WITH FAILING CODE

preguntado el 04 de diciembre de 12 a las 04:12

Hi you can use, onChange listerner of that textfield and change the value of that textfield using the javascript. -

I tried something like that but received an error saying "cannot read property 'value' or undefined" maybe you could help me with the javascript? -

can you post the code what have you tried / -

1 Respuestas

Reemplazar la línea

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

by

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

Y haz algo como

function decodeURI(elm) {
    elm.value = 'foo ' + elm.value + ' bar';
    return false;
}

Respondido el 04 de diciembre de 12 a las 05:12

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.