0

I need to reload a page when a checkbook is clicked. If the checkbox was unchecked before clicking then it should be checked after the page reloads. If the checkbox was checked then after clicking the page should reload and the checkbox should be unchecked.

Moreover, I need to pull the information (if is checked or unchecked) from the checkbox to change my page accordingly.

How can I reload the page and pass this values changing this function? I am complete noob so please try to stay simple. Ty.

      echo '<input id="check_mostra_email" type="checkbox" value="mostra_email" onclick="reloadPage()"/>';  

      echo '<script type="text/javascript">
        <!--
           function reloadPage()
           {
              if(document.getElementById("check_mostra_email").checked === true){
                document.forms["RelatorioGerencialCarteiras007"].submit();
                }

              else{
                document.forms["RelatorioGerencialCarteiras007"].submit();
                } 
           }
        //-->
     </script>'; 
Ihidan
  • 558
  • 1
  • 7
  • 25
  • If you inputs are in the form, then you should be able to give them a name that your server can pick up and when you re-render the page just set/unset the checked attribute as needed. Though a better solution would be to read up on Ajax and just reload the parts of the page that you need refreshed.. – scrappedcola Aug 25 '15 at 14:03
  • 1
    Seems you have a design problem, you should not reload the page when check/uncheck a box, just display or not some info, or use ajax to load a html content. – Tony Aug 25 '15 at 14:06

1 Answers1

0

Why aren't you using PHP for this?

In your case after your reload you have a $_POST or $_GET variable which shows you if the checkbox was checked or not.

xeno
  • 44
  • 5
  • This is not an answer to the question. It is very common these days to use JavaScript before a form or something gets send to the server. – KittMedia Aug 25 '15 at 14:07