1

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?

14
  • 1
    With no server-side language, like PHP, you can't. Commented Apr 24, 2014 at 16:36
  • 1
    Without 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. Commented 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? Commented Apr 24, 2014 at 16:37
  • 2
    Be 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 cookies Commented 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. Commented Apr 24, 2014 at 16:43

2 Answers 2

2

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.

Sign up to request clarification or add additional context in comments.

8 Comments

And is there a way to pass that email from the storage? Any way. The thing is I really need to store user credentials.
@egyeneskanyar You can pass it around within the same page using AJAX, but to other pages you have to pass it to the server or put it in a cookie, there is no other way.
May I ask what can I do with the stored e-mail furthermore? Or I should ask, what do you suggest? Is there any way to pass it to some kind of database, or a php page that will be able to process it?
@egyeneskanyar Yeah calling the retrieveEmail function above will store it back into the var email. From there you could pass it to anywhere you need to by doing an ajax call. I will add a simple example of that.
Oh, and with the ajax call I can just use my external PHP file to process the info. I guess. It is not a problem to use an outer file as long as I can call it via this html file & I can pass it the value.
|
-1

You could always use Javascript to create a text file where you can save information...

1 Comment

Most browsers aren't going to let you do this by default as it's a massive security risk. ActiveX in ie browsers can do something similar and there are other tools available, but the end user has to agree to install them first. I don't think this is a good idea.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.