C Doug C Doug - 3 months ago 6
HTML Question

How to initialize an element in an HTML page

I want to pass through the text data entered on the /index page (property address) and (email) to the /sign-up page.

problem:

The query string(s) are moving into the URL, however how do I populate the respective fields on the /sign-up page, with the text data provided in the URL?

www.juwai.kiwi

<script>
(function(f, e, t){
initForm(f, e, t);
}(document.forms[0],'full_name',document.getElementsByName('full_name').valueOf()));
</script>
<script>
function initForm(oForm, element_name, init_txt) {
frmElement = oForm.elements[element_name];
frmElement.value = init_txt;
};
var queryStrng = [
{
full_name: "dave",
email: "email@to.do",
property_address: "prop address to do"
}
];
//queryStrng[0].full_name = document.getElementsByName("full_name").valueOf();
//var oFormObject = document.forms[0];

</script>

Answer

Try this function:

function GetURLParameter(sParam)
{
    var sPageURL = window.location.search.substring(1);
    var sURLVariables = sPageURL.split('&');
    for (var i = 0; i < sURLVariables.length; i++) 
    {
        var sParameterName = sURLVariables[i].split('=');
        if (sParameterName[0] == sParam) 
        {
            return sParameterName[1];
        }
    }
}‚Äč


 And this is how you can use this function assuming the URL is, 
http://www.juwai.kiwi/sign-up.html?property_address=abcd&email=myemail%40gmail.com

var property_address = GetURLParameter('property_address');
var email = GetURLParameter('email');`