Except the fact I am not able to use PHP. I have a single HTML file I can work with. So the only way is JS I think. And I have an "email" user input where the user sets his email and the n he is able to proceed, but I have to save his email first. Any ideas?
-
1With no server-side language, like PHP, you can't.j08691– j086912014-04-24 16:36:26 +00:00Commented Apr 24, 2014 at 16:36
-
1Without PHP there's no way to store the data server side, but you could use localStorage if it will work for what you're trying to do.APAD1– APAD12014-04-24 16:37:18 +00:00Commented Apr 24, 2014 at 16:37
-
do you have access to anywhere else where you can create a PHP file to send the email address to do using AJAX?Peter Featherstone– Peter Featherstone2014-04-24 16:37:37 +00:00Commented Apr 24, 2014 at 16:37
-
2Be more specific please on where do you want to store the data, if you want to store it server-side, for sure you need some server side platform of whatever u wish ( i.e java, node.js, ruby, etc,,, anything where you manage to handle http requests - it doesnt necessarely needs to be php) - if you just want to store it locally, well, use localStorage or old fashioned cookiesEnoque Duarte– Enoque Duarte2014-04-24 16:43:29 +00:00Commented Apr 24, 2014 at 16:43
-
Peter: yes, I think. But I'm afraid using localStorage would not be a wise method since I can't really operate on the server, nor the host, I can just modify the simple html file, like on some blog page.egyeneskanyar– egyeneskanyar2014-04-24 16:43:49 +00:00Commented Apr 24, 2014 at 16:43
2 Answers
If you only need to save the element in a short term way you can use javascript and the HTML5 data element to save the email as an element of the current page. It is very temporary storage, but is the best you're going to get.
Edit: Here's how you can do this using jQuery based javascript.
HTML:
<input type="text" id="email">
<input type="button" id="emailButton">
<div id="data_div"></div>
jQuery Javascript:
function retrieveEmail() {
var email = $('#data_div').data("email");
// do something with the email variable as needed here
// here's an example of retrieving it to send it to the server
var paramStr = "email=" + email;
$.ajax({
url: './your_server_file_here',
dataType: 'json',
data: paramStr,
success: function(data) {
callBack(data);
});
}
function callBack(data) {
// do something with information passed back from the server after you sent the data to the server (you didn't say you needed to do this, but here's where it should be done)
}
function storeEmail() {
var email = $('#email').val();
$('#data_div').data("email", email);
}
$(document).ready( function() {
$('#emailButton').click( function() {
storeEmail();
});
});
Edit: I know you already accepted this answer, but it struck me that HTML5 also includes another way to do this and it may provide the increase in power and flexibility that you're looking for. The HTML5 storage element can do pretty much the same thing as the data element except that it can persist and be accessed by other pages from the same domain either until the browser is closed (unlimited amount of data in the sessionStorage) or indefinitely (5mb of data in the localStorage). For implementation details and a greater understanding see here.
Be advised though, the HTML5 storage element is only available in HTML5 compatible browsers and should not be used if you fear your user base won't be using a modern browser. The HTML5 Data element will work even in older browsers, so it does have that advantage.
8 Comments
You could always use Javascript to create a text file where you can save information...