Monday, July 5, 2010

Javascript to fetch and submit data

This script will fetch data from the input fields of a web site and submit the data as a query string to a URL of your choosing:

javascript:
var lastname_elem = document.getElementById
('ctl00_ContentPlaceHolder1_txtLName');
var lastname = lastname_elem.value;
alert(lastname);

var firstname_elem = document.getElementById
('ctl00_ContentPlaceHolder1_txtFName');
var firstname = firstname_elem.value;
alert(firstname);

var dob_elem = document.getElementById
('ctl00_ContentPlaceHolder1_txtDOB');
var dob = dob_elem.value;
alert(dob);

open('http://example.com?lastname='+lastname+
'&firstname='+firstname+
'&dob='+dob,
'_self',
'resizable,location,menubar,toolbar,scrollbars,status');

You just need to find out the element id for the input fields. This example pops the data from the input fields into alert text boxes before submitting the get request to the next web site, for debugging purposes.

No comments:

Post a Comment