I have created few scripts to complete a web registration. Now each time I complete a registration on the last step it generates a 'Registration ID'. I need to capture and save this id to a file. Can we do this with JavaScript?
3 Answers
To get the registration id you can save it t a hidden element [textbox with type hidden] and get the value using javascript like this.
document.getElementById ( "txtHidRegID" ).value;
where the id of the textbox is txtHidRegID.
For the second part [file save] you cannot access files on the client side using javascript. You can save it to a file on the server side using any server side language.
Accessing file in a client machine using javascript which runs inside a sandbox will be a security hole.
Comments
If you wish to save the ID to the server side, you can do that by throwing an Ajax request with the value to a server-side script which will save the value.
If you wish to save to a local file (client-side), then you need more than JavaScript.
To get the registration ID, use the DOM with getElementById.