View Full Version : Grabbing value from URL

12-23-2006, 12:14 AM
Right now... i have it to where it grabs the value username by putting in a div.
(For example if i do <div name="John" id="name" style="display:none;">) it will make the value for username John .... i did that by doing this line of javascript:

function getusername(){var name_div=document.getElementById('name');if(name_div){var username=name_div.getAttribute('name');if(username)return username;}var i,j,h,s;h=document.location.href;s='usrn=';i=h.indexOf(s);if(i==-1)return '';i+=s.length;j=h.indexOf('&',i);if(j==-1)return '';return h.substring(i,j);}

What will i have to change in that code to get username from the URL by going for example http://site.com/file.html?name=John (with file.html having the javascript on it) or http://site.com/file.html?name=Bob ... (wich will make the value for getusername Bob)

More/less , i would like to do ?name=USERNAME in a URL instead of having to do <div name="USERNAMEHERE" id="name" style="display:none;">

12-23-2006, 02:58 AM