Change CSS on different page based on condition using Javascript/JQuery -
on first page have onclick event adds class called message form.
<input type="button" onclick="isdirty()" class="btn btn-default" /> <script> function isdirty() { $('form').addclass('message'); } </script> then have if statement uses jquery check if form has class:
if ($('form').hasclass('message')) { $("#commentandfilemessage").show(); } if does, 'display: none;' css element of paragraph on page 2 should change show:
<p id="commentandfilemessage">you must save new license on details page.</p> i'm sort of new javascript, i'm thinking isn't possible without cookie or something. know if can work? thanks!
yes possible without cookies, using html5 localstorage(which supports modern browsers). on first page set localstorage,code shown below
function isdirty() { $('form').addclass('message'); localstorage.setitem("form", "message");//page1, set localstorage form , messages key-value pairs } then on page2 , value localstorage
if(localstorage.getitem("form") == "message") { $("#commentandfilemessage").show(); }
Comments
Post a Comment