merch89 merch89 - 1 month ago 6
HTML Question

Running Jquery within a PHP function

I have a form that has form entries and submission confirmation on the same page. When submitted, currently the form entries remain when my submission message displays - so I wish to use Jquery to hide the form entries. My form has the the id of #mysubscription, can anyone spot why this form isn't clearing on submission?

<?php
}

if (isset($contact_form_submitted) && $contact_form_submitted) {
?>
<p class="success"><strong><?php echo htmlspecialchars((isset($contact_form_message)) ? $contact_form_message : 'Submission successful.', ENT_QUOTES, 'utf-8'); ?></strong></p>
<script type="text/javascript">jQuery('#mysubscription').hide()</script>

<?php
}
?>

Answer

Try this

<!--You need to load library first without library $ wont work-->    
    <script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
    <script type="text/javascript">
      /**
      * $(function(){}) is runs the script after DOM(document object model) loaded. this equivalent to ready() function. The ready() method specifies what happens when a ready event occurs.    
      */
       $(function(){ 
          $('#mysubscription').hide();
        });
    </script>