shir11 Posted September 23, 2014 Share Posted September 23, 2014 Hi all, I have an input button and I want that if the user click this button in the second time - someting will happen. how can I count 2 clicks? is there "session" in javascript? thank you:) Link to comment Share on other sites More sharing options...
Ingolme Posted September 23, 2014 Share Posted September 23, 2014 There's localStorage and sessionStorage. Link to comment Share on other sites More sharing options...
shir11 Posted September 23, 2014 Author Share Posted September 23, 2014 is it only for html5? Link to comment Share on other sites More sharing options...
Ingolme Posted September 23, 2014 Share Posted September 23, 2014 It's available in any browser that has support for HTML 5, but it's Javascript, so you can use it even if your page is HTML 4.01 or XHTML Link to comment Share on other sites More sharing options...
shir11 Posted September 25, 2014 Author Share Posted September 25, 2014 thank you!I wrote that code:1. <script type="text/javascript">2. $(document).ready(function () {3. $("#submit").on("click", function () {4. if (sessionStorage.clickcount) {5. sessionStorage.clickcount = Number(sessionStorage.clickcount) + 1;when I click on the button and debug - I reached to line no. 4 and that's it.why if (sessionStorage.clickcount) always false? Link to comment Share on other sites More sharing options...
thescientist Posted September 25, 2014 Share Posted September 25, 2014 if it's equal to 0, then it will evaluate to false. Link to comment Share on other sites More sharing options...
shir11 Posted September 26, 2014 Author Share Posted September 26, 2014 I work in chrome and it gives me this: sessionStorage.clickcount is undefind. why is that? Link to comment Share on other sites More sharing options...
Ingolme Posted September 26, 2014 Share Posted September 26, 2014 Did you ever define it at any moment? Link to comment Share on other sites More sharing options...
shir11 Posted September 27, 2014 Author Share Posted September 27, 2014 yes, it's undefined all the way.. Link to comment Share on other sites More sharing options...
Ingolme Posted September 27, 2014 Share Posted September 27, 2014 Then give it a value. Write this somewhere: sessionStorage.clickcount = 0; You can't really use a variable if you don't give it a value. Link to comment Share on other sites More sharing options...
shir11 Posted September 28, 2014 Author Share Posted September 28, 2014 YES!! thank you so much!!! Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now