Receiving Form Data

This demo page retrieves the data that you entered in the demo_form1.htm file. Form names and values are extracting from the URL for this page using the location.search property and the slice() method. The + symbol in the field values (used to represent a blank space) is replaced with a blank space. Finally, the text string is split into individual field names and values using the split() method. The following function is run when the page is loaded by the browser:

function retrieveData() {
   searchString = location.search.slice(1);
   searchString = unescape(searchString);
   formString = searchString.replace(/\+/g, " ");
   data = formString.split(/[&=]/g);
   document.dform2.name.value=data[1];
   document.dform2.age.value=data[3];
   document.dform2.city.value=data[5];
}
1) Your name is
2) Your age is
3) Your city of residence is
Carey, P. New Perspectives on JavaScript, Course Technology: Boston, 2005.