Jump to content

Include Js Using Sethtml


Radix

Recommended Posts

Hi again,

 

i wanted to ask..is it possible to embed js code in blesta module function?

 

I tried to include javascript code using setHtml function but somehow it is not being called.

 

Can you provide me some hints as to how i can achieve this?

Link to comment
Share on other sites

Hi again,

 

i wanted to ask..is it possible to embed js code in blesta module function?

 

I tried to include javascript code using setHtml function but somehow it is not being called.

 

Can you provide me some hints as to how i can achieve this?

 

there are some module have a sample like cpanel .

 

can you post your sethtml() ?

Link to comment
Share on other sites

$fields->setHtml("
                <script type = \"text/javascript\" src = \"/path-to-js/jquery.min.js\"></script>
                <script type = \"text/javascript\">
                    $(window).load(function(){
                        $(\"#selectId\").prepend(\"<option value=''>__Select option__</option>\").val(' ');
                    });
                    </script>        
        ");

 

I am trying to append an option in the dropdown list using prepend function.

 

Let me know if there's something wrong

Link to comment
Share on other sites

I suppose you change this path-to-js to your real path,maybe dumb question but just in case

 

$fields->setHtml("
                <script type = \"text/javascript\" src = \"/path-to-js/jquery.min.js\"></script>
                <script type = \"text/javascript\">
                    $(window).load(function(){
                        $(\"#selectId\").prepend(\"<option value=''>__Select option__</option>\").val(' ');
                    });
                    </script>        
        ");

Link to comment
Share on other sites

I apologize for a foolish question but do i have to include the jquery file in "/app/view/admin/default/javascript/" when i embed js in module or does it parse automatically??

 

That js src path was just for example.

src/source path in your code is path to jquery file and valid path should point  to jquery.min.js in that example,in short path is valid if it point to jquery file.

If your file is on localhost in blesta directory than you will put path to that file as source,if your file is on remote host than you will put url and path to file on remote host as source.

EDIT;

Glad to see you fix it,I sow your update little late

Link to comment
Share on other sites

the code you have pas should be like this :

$fields->setHtml("
                <script type = 'text/javascript' src = '/path-to-js/jquery.min.js'></script>
                <script type = 'text/javascript'>
                    $(window).load(function(){
                        $('#selectId').prepend(\"<option value=''>__Select option__</option>\").val();
                    });
                    </script>       
        ");
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...