Note that there are some explanatory texts on larger screens.

plurals
  1. POjavascript keep checkbox checked after refresh page
    primarykey
    data
    text
    <p>hi i am javascript newbie.</p> <p>I have checkbox that slideDown other input , i want to keep that checkbox checked and the other input showed after refreshing the page if the input checkbox checked</p> <p><strong>javascript:</strong></p> <pre><code>function validateSitec(){ if (document.getElementById('sitecheck').checked){ $('#sitecheck').prop('checked', true); $('#closedmsg').slideDown(); }else{ $('#closedmsg').slideUp(); $("#sitecheck").removeProp("checked").checkboxradio("refresh"); } } </code></pre> <p><strong>this my inputs:</strong></p> <pre><code>&lt;label for="sitecheck"&gt; &lt;span style="font-weight:bold;"&gt;close site+ msg:&lt;/span&gt; &lt;/label&gt; &lt;input name="" type="checkbox" id="sitecheck" onclick="validateSitec()" /&gt;&lt;span style="font-weight:bold;"&gt;click to activate msg&lt;/span&gt;&lt;br&gt; &lt;input type="text" name="closedmsg" id="closedmsg" style="width:440px;height:120px;display:none;" value="enter closed msg.."/&gt; </code></pre> <p>i want if checked stay checked.. and wont change after refreshing the page , then when unchecked so back to normal and be unchecked when refreshing the page..</p> <p>should i use php for making it not change after checking with javascript?</p> <p><strong>Edited:</strong></p> <p>Thanks to all for helping credit goes to : leiyonglin .</p> <p>The working code for anyone who like to use it:</p> <p>download first: <a href="https://github.com/carhartl/jquery-cookie" rel="nofollow">https://github.com/carhartl/jquery-cookie</a></p> <p>then use this codes working awesome :</p> <p>JavaScript:</p> <pre><code>&lt;script type="text/javascript"&gt; function validateSitec(){ if (document.getElementById('sitecheck').checked){ $('#sitecheck').prop('checked', true); $('#closedmsg').slideDown(); $.cookie("cookieChecked", "#sitecheck"); }else{ $('#closedmsg').slideUp(); $("#sitecheck").removeProp("checked"); $.cookie("cookieChecked",""); } } $(function(){ var cookieChecked = $.cookie("cookieChecked"); if(cookieChecked){ $('#sitecheck').prop('checked', true); $('#closedmsg').show(); }else{ $("#sitecheck").removeProp("checked"); $('#closedmsg').hide(); } }) &lt;/script&gt; </code></pre> <p>html inputs:</p> <pre><code>&lt;label for="sitecheck"&gt; &lt;span style="font-weight:bold;"&gt;close site temp:&lt;/span&gt; &lt;/label&gt; &lt;input name="" type="checkbox" id="sitecheck" onclick="validateSitec()" /&gt;&lt;span style="font-weight:bold;"&gt;close site and add message&lt;/span&gt;&lt;br&gt; &lt;input type="text" name="closedmsg" id="closedmsg" style="width:440px;height:120px;display:none;" value="&lt;?php echo $data['csitemsg']; ?&gt;" /&gt; </code></pre> <p>This working perfect thx again all.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload