Reputation: 7703
I am having two HTMLs step1.html
and step2.html
and I am passing latin value(envían
)from step1.html
to step2.html
via URL query string by having the to be passed value(envían
) in input field value(which is in hidden state in step1.html
.
I am getting the value of the query string parameter in step2.html
using some utility function and I am displaying the value in one textbox but i got the value in textbox as different from the value passed see the screenshot.
Got encoded value for í
, help me to get the same value í
in step2.html
also.
EDIT: One disadvantage is step2.html
is twitter.com, there i cannot do any decoding. see the screenshot below
Thanks in advance for any help.
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
<head>
</head>
<body>
<div class="">
<form action="step2.html">
<input type="submit" value="click to submit"/>
<input type="hidden" name="val" value="envían" />
</form>
</div>
</body>
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
<head>
<script>
var QueryString = function () {
// This function is anonymous, is executed immediately and
// the return value is assigned to QueryString!
var query_string = {};
var query = window.location.search.substring(1);
var vars = query.split("&");
for (var i=0;i<vars.length;i++) {
var pair = vars[i].split("=");
// If first entry with this name
if (typeof query_string[pair[0]] === "undefined") {
query_string[pair[0]] = pair[1];
// If second entry with this name
} else if (typeof query_string[pair[0]] === "string") {
var arr = [ query_string[pair[0]], pair[1] ];
query_string[pair[0]] = arr;
// If third or later entry with this name
} else {
query_string[pair[0]].push(pair[1]);
}
}
return query_string;
} ();
function fngetval(){
var val=QueryString.val;
document.getElementById("status").value=val;
}
</script>
<style>
</style>
</head>
<body onload="fngetval();">
<div class="">
<textarea id="status" name="status" ></textarea>
</div>
</body>
Upvotes: 0
Views: 969
Reputation: 18891
You cannot have the í
in a URL, thus why it is encoded into %ED
.
You can either 1) use a POST
form instead of the default GET
. or 2) decode the value of the val
variable. See this Stack Overflow question: JavaScript URL Decode function.
Upvotes: 1