Reputation: 11
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?
Upvotes: 1
Views: 597
Reputation: 3665
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.
Upvotes: 2
Reputation: 53929
Not directly with JavaScript. You will have to send your generated id to the server somehow. You could use XHR (AJAX) if you don't wish to refresh the page.
Upvotes: 1
Reputation: 187110
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.
Upvotes: 2