943,169 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Marked Solved
  • Views: 418
  • PHP RSS
Sep 2nd, 2010
0

how to stop a div(display:none) from displaying on pressing a back button on browser

Expand Post »
hi,
i have a page which shows user details(div1) by default
there will be an admin who enters username and pwd and then a new div(div-layer) is displayed.
also ,a user can edit his data by pressing edit button on which he will be displayed div2 and div1 will be hidden.
mt problem is when i try checking all these one by one they work perfectly except for when i enter admin username and pwd and tell a user to fill in more details and then assume myself as a user and edit the data...at this point when i go back(i mean press back button on mozilla browser)...all my divs are visible(even the div layer which should be visible after admin authentication) irrespective of their display settings.i tried disabling the back button..but mozilla doesn't allow js to modify that.please suggest a solution.



PHP Syntax (Toggle Plain Text)
  1. <html>
  2. <head>
  3. <script type = \"text/javascript\">
  4. function hideDiv(which) {
  5. if (which == 1) {
  6. document.getElementById(\"div1\").style.display=\"block\";
  7. document.getElementById(\"div2\").style.display=\"none\";
  8. }
  9. if (which == 2) {
  10. document.getElementById(\"div2\").style.display=\"block\";
  11. document.getElementById(\"div1\").style.display=\"none\";
  12. window.history.forward(1);
  13. }
  14. }
  15. </script>
  16. </head>
  17. <body>
  18. <div id="divedit">
  19. <input value=\"edit\" type=\"button\" name=\"edit\" onClick= \"hideDiv(2);\"/>
  20. .........
  21. </div>
  22. <div id="div1">
  23. ........
  24. </div>
  25. <div id="div2">
  26. ........
  27. </div>
  28. <div id="div3">
  29. username:<input type="text" name="uname"/></br>
  30. password:<input type="password" name="uname"/>
  31. <input value="submit" type="submit" name="submit"/>
  32. </div>
  33. <div id="layer" class="layer" style="display:<?php if(isset($_POST['submit'])) {echo (($_POST['uname'] =='deepthi' && $_POST['pwd']=='deepthi')? 'block' : 'none'); } else {echo 'none';} ?>;">
  34. .....
  35. <body>
  36. </html>
  37.  
Last edited by saideepthi.bits; Sep 2nd, 2010 at 5:22 am.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
saideepthi.bits is offline Offline
9 posts
since Sep 2010
Sep 2nd, 2010
0
Re: how to stop a div(display:none) from displaying on pressing a back button on browser
you should post this in the javascript area of this website
Reputation Points: 10
Solved Threads: 2
Newbie Poster
CyberSpatium is offline Offline
9 posts
since Sep 2010
Sep 6th, 2010
0
Re: how to stop a div(display:none) from displaying on pressing a back button on browser
you should post this in the javascript area of this website

yes, but my problem is ...in display:none,i have written a php check function which is not executing when back button is pressed...i mean it should check the condition every time the page is loaded right..?is hitting back button on your browser not equivalent to loading the page..? plz help...thanx in advance
Reputation Points: 10
Solved Threads: 0
Newbie Poster
saideepthi.bits is offline Offline
9 posts
since Sep 2010
Sep 6th, 2010
0
Re: how to stop a div(display:none) from displaying on pressing a back button on browser
The back button tries to reload the previous page exactly as it was. Theoretically it should refire the php but given I've never had this problem, or tried doing it this way, I can't say it will work perfectly. This is also a js problem, not a php as php doesn't have any control over a page once it's been downloaded (is being viewed).

However, a possible solution would be to initially change all the div's display to none and then update from there. Or you can use jQuery.

[Links]
http://www.jquery.com/
Last edited by Nyight; Sep 6th, 2010 at 1:26 am.
Reputation Points: 23
Solved Threads: 21
Junior Poster in Training
Nyight is offline Offline
99 posts
since Aug 2010
Sep 6th, 2010
0
Re: how to stop a div(display:none) from displaying on pressing a back button on browser
Click to Expand / Collapse  Quote originally posted by Nyight ...
The back button tries to reload the previous page exactly as it was. Theoretically it should refire the php but given I've never had this problem, or tried doing it this way, I can't say it will work perfectly. This is also a js problem, not a php as php doesn't have any control over a page once it's been downloaded (is being viewed).

However, a possible solution would be to initially change all the div's display to none and then update from there. Or you can use jQuery.

[Links]
http://www.jquery.com/
so, you are basically saying that doing this in js will be a better idea...but my problem is that i take username and password and match them to admin data and then display the div ...anyways i'll try js and get back to you...thanx
Reputation Points: 10
Solved Threads: 0
Newbie Poster
saideepthi.bits is offline Offline
9 posts
since Sep 2010
Sep 6th, 2010
0
Re: how to stop a div(display:none) from displaying on pressing a back button on browser
Truthfully I have no idea what you're trying to accomplish with the admin concept or why you have everything in your posted code commented out. I assumed your problem was that everything became visible when you clicked the back button. A simple solution to that would be to set everything to hidden at the top of the page (the very first thing js does) and then check to see if it should be shown.
Reputation Points: 23
Solved Threads: 21
Junior Poster in Training
Nyight is offline Offline
99 posts
since Aug 2010
Sep 8th, 2010
0
Re: how to stop a div(display:none) from displaying on pressing a back button on browser
Click to Expand / Collapse  Quote originally posted by Nyight ...
Truthfully I have no idea what you're trying to accomplish with the admin concept or why you have everything in your posted code commented out. I assumed your problem was that everything became visible when you clicked the back button. A simple solution to that would be to set everything to hidden at the top of the page (the very first thing js does) and then check to see if it should be shown.

oh sorry..i didnot notice "\" . now my problem is that i have declared the display of the divs hidden and it works fine except for when i am navigating through the pages and hit back button on the browser, i see all the divs even those which are supposed to be hidden.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
saideepthi.bits is offline Offline
9 posts
since Sep 2010
Oct 4th, 2010
0
Re: how to stop a div(display:none) from displaying on pressing a back button on browser
Click to Expand / Collapse  Quote originally posted by Nyight ...
Truthfully I have no idea what you're trying to accomplish with the admin concept or why you have everything in your posted code commented out. I assumed your problem was that everything became visible when you clicked the back button. A simple solution to that would be to set everything to hidden at the top of the page (the very first thing js does) and then check to see if it should be shown.

hi, thanx a lot..."declaring div display initially in js and calling the function on form onload" solved my problem....i havent got time to reply back...thanx again
Reputation Points: 10
Solved Threads: 0
Newbie Poster
saideepthi.bits is offline Offline
9 posts
since Sep 2010

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: PHP Project Help!!
Next Thread in PHP Forum Timeline: how to make a php link which will open in new tab





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC