Fill Form Hidden Field with Querystring Paramater


I have need to populate a hidden field on a Form with a value from incoming querystring with javascript.
I used the script I found from this thread to get the job done.
http://www.webmasterworld.com/javascript/4313611.htm

 
function getquerystring() {
    var url = location.href;
    if (url.split('?')[1] != undefined) {
        var qs = url.split('?')[1];
        String.prototype.splitquerystring = function () {
            return this.split(/[=&]/);
        }
        document.getElementById('promocode').value = qs.splitquerystring()[1];

//        for (var c = 1; c < qs.splitquerystring().length; c += 2) {

//            document.getElementById('inp' + c).value = qs.splitquerystring()[c]; 
//        } 

    }
}
window.addEventListener ? window.addEventListener('load', getquerystring, false) : window.attachEvent('onload', getquerystring); 
  


Advertisements


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s