Reputation: 138
I need a JavaScript solutions. I recived data from aweber after user subscribe, in success page. so url like:
http://example.com/success/[email protected]&name=Jhon&custom_phone=0005551114&custom_location=USA
They give some javascript solutions to show data in webpage or success page...
So When I put
<script type="text/javascript">formData.display("name")</script>
<script type="text/javascript">formData.display("email")</script>
<script type="text/javascript">formData.display("custom_phone")</script>
<script type="text/javascript">formData.display("custom_location")</script>
value will show in my page. But How can I put the value in a input field in success page??
<form action="" method="post">
<input type="text" name="username" value="Jhon">
<input type="text" name="useremail" value="[email protected]">
<input type="text" name="phoneno" value="0005551114">
<input type="text" name="country" value="USA">
<input tyoe="submit" value="Submit">
</form>
Please help..
Upvotes: 0
Views: 188
Reputation: 4774
You can change the Javascript code a bit, like this:
<script type="text/javascript">
var formData = function() { var query_string = (location.search) ? ((location.search.indexOf('#') != -1) ? location.search.substring(1, location.search.indexOf('#')) : location.search.substring(1)) : '';
var elements = [];
if(query_string) {
var pairs = query_string.split("&");
for(i in pairs) {
if (typeof pairs[i] == 'string') {
var tmp = pairs[i].split("=");
var queryKey = unescape(tmp[0]);
queryKey = (queryKey.charAt(0) == 'c') ? queryKey.replace(/\s/g, "_") : queryKey;
elements[queryKey] = unescape(tmp[1]);
}
}
}
return {
display: function(key) {
if(elements[key]) {
document.write('<input type="text" name="' + key + '" value ="' + elements[key] + '"');
}
else {
document.write("<!--If desired, replace everything between these quotes with a default in case there is no data in the query string.-->");
}
}
}
}
(); </script>
And your HTML will look like this:
<form action="" method="post">
<script type="text/javascript">formData.display("name")</script>
<script type="text/javascript">formData.display("email")</script>
<script type="text/javascript">formData.display("custom_phone")</script>
<script type="text/javascript">formData.display("custom_location")</script>
<input tyoe="submit" value="Submit">
</form>
Upvotes: 1