Jump to content

add bunch of jquery inline codes in prestashop module file not working


Recommended Posts

I am just newbie to the prestashop. Currently I am creating a small module in prestashop. I want to add some jQuery inline codes to the modulename.php file. But its not working there. Can someone kindly tell me how to use jQuery codes to the prestashop module files. Any help and suggestions will be really apprecaible. Thanks

 

My sample code goes like this

 

   public function getContent() {
         $this->_html = '<h2>'.$this->displayName.'</h2>';

       if (Tools::isSubmit('submitUpdate')) {
         Db::getInstance()->Execute('UPDATE `'._DB_PREFIX_.'tablename` SET `function_name`="'.$body_option.'",`height`="'.$height.'",`width`="'.$width.'"');

         $this->_displayForm();
         return $this->_html;
       }
     });

 

 

     private function _displayForm() {
       $this->_html .=  '
         <link rel="stylesheet" href="../modules/modulename/css/store_styles.css" />
         <script src="../modules/modulename/js/jquery-1.7.2.min.js" type="text/javascript"></script>';

         $this->_html .= '<input type="file" name="file" id="file"  multiple/>';

       $this->_html .= '
         <form method="post" action="'.$_SERVER['REQUEST_URI'].'" id="test">';

       $this->_html .= '<div class="clear"></div></div>
         <label>'.$this->l('Upload Image').' </label>
         <div class="margin-form">';
         $this->_html .= '<input type="file" name="file" id="file"  multiple/>';
         $this->_html .= '</div>';

           $this->_html .= '
           <div class="margin-form clear"><input type="submit" name="submitUpdate" value="'.$this->l('Save').'" class="button" /></div>
           </form>      
     }

 

 

So as per my requirment when I will click on checkbox then this piece of code should work.

 

 

 

<script type="text/javascript">
     jQuery('input[name="file"]').change(function(){
       if(jQuery(this).val() == 'yes'){
         jQuery('input[type="file"]').prop('multiple', true);
       }else{
           jQuery('input[type="file"]').prop('multiple', false);
       }
     });
   </script>

Remember That this form is for admin and I want the piece of jQuery codes in the backend.

Link to comment
Share on other sites

if you've got some troubles with script, turn on browser console, you will see where exactly problem occur

you can paste error code from browser console here

 

thanks vekia for the reply but when I simply tried

 

<script type="text/javascript">
     jQuery(document).ready(function() {
       jQuery(console.log('hello'));
     });
   </script>

after the form. Then I got the error like [PrestaShop] Fatal error in module syntax error, unexpected '<' (this line is where I have started <script type tag

Link to comment
Share on other sites

×
×
  • Create New...