0

I am trying to build a simple html app getting some basic customer information and storing the information in database. After capturing the information, when the customer logs in his profile, he can see 3 buttons.

button 1= print

button 2= delete

button 3= edit

Special requirement:

  • Unless button 1 is clicked,
  • Then button 2 and 3 should be disabled for the first time user logs in.

For the next subsequent logins

  • All buttons should be enabled.

So far I have done the below thing:

<html>
<head>
    <script>
        function enableButton() {
          document.getElementById("button2").disabled = false;
          document.getElementById("button3").disabled = false;
        } 
    </script>
</head>
<body>
    <input type="button" id="button1" value="print" onclick="enableButton()"  />
    <input type="button" id="button2" value="delete" disabled />
    <input type="button" id="button3" value="edit" disabled />
</body>
</html>

But this doesn't take care of the requirement described above. Any help would be appreciated

Ryan Vincent
  • 4,483
  • 7
  • 22
  • 31
tourist
  • 11
  • 4

3 Answers3

1

use HTML5 localStorage or Javascript cookie to fulfill the requirement as it is totally based on user login.

Steps you have to follow :

  1. When user login first time create a fresh cookie or setItem in localstorage as new.
  2. When user login second time set a cookie value or setItem in localstorage as old.

By doing this you can identify which one is new user and which one is older and do functionality according to that.

Debug Diva
  • 26,058
  • 13
  • 70
  • 123
0

Using localStorage might be a workaround since you did not described any use of a server-side session retrieval

var trueOnFirstVisit = window.localStorage.firstVisit || "true";   
$("#button2, #button3").prop("disabled", trueOnFirstVisit);
window.localStorage.firstVisit = "false";

So, if we have a localStorage value of "false" means the user already visited the page.

https://developer.mozilla.org/en/docs/Web/API/Window/localStorage
http://api.jquery.com/prop/

Roko C. Buljan
  • 196,159
  • 39
  • 305
  • 313
0

Assuming you already have stored the information when the user logged in you can access this using $.cookie('varible_name'); if you used cookies.

You can also send a post request and using rpc $.post(...) and check if the user has logged in. If subsequent log ins means separate log in rather than persistent you can keep a counter on the login table in the database and update/fetch this as required.

Luis
  • 114
  • 2
  • 10