Custom button not working

General questions relating to Joomla! 2.5. Note: All 1.6 and 1.7 releases have reached end of life and should be updated to 2.5. There are other boards for more specific help on Joomla! features and extensions.

Moderator: General Support Moderators

Forum rules
Forum Rules
Absolute Beginner's Guide to Joomla! <-- please read before posting.
Forum Post Assistant - If you are serious about wanting help, you should use this tool to help you post.
Locked
User avatar
emanipur
Joomla! Explorer
Joomla! Explorer
Posts: 392
Joined: Sat Jun 09, 2012 10:58 am
Location: Imphal
Contact:

Custom button not working

Post by emanipur » Wed Jul 02, 2014 4:43 pm

Hello.
I am trying to use jsPDF to print certain div into PDF.
I have included all the required files in the head section and the required script declaration as

Code: Select all

<script type="text/javascript"> 
var doc = new jsPDF(); var specialElementHandlers = {     '#editor': function (element, renderer) {         return true;     } };  $('#cmd').click(function () {     doc.fromHTML($('#content1').html(), 15, 15, {         'width': 170,             'elementHandlers': specialElementHandlers     });     doc.save('sample-file.pdf'); });</script>
And in the HTML part, i have added the following codes

Code: Select all

<div id="content">
     <h3>Hello, this is a H3 tag</h3>
    <p>a pararaph</p>
</div>
<button id="cmd" >generate PDF</button>
The code print out the div content as PDF document. The above code works on a standalone HTML file, but when i try to integrate it with Joomla, the button doesnt do anything, except it just reloads the page.

I think i am doing some wrong in doing this, Can anyone guide me?
Below is my test.html code which works...

Code: Select all

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.1/jquery.min.js" type="text/javascript"></script>             
<script type="text/javascript" src="https://raw.githubusercontent.com/MrRio/jsPDF/master/dist/jspdf.min.js"></script>
<script type="text/javascript">
var doc = new jsPDF();
var specialElementHandlers = {
    '#editor': function (element, renderer) {
        return true;
    }
};

$('#cmd').click(function () {
    doc.fromHTML($('#content').html(), 15, 15, {
        'width': 170,
            'elementHandlers': specialElementHandlers
    });
    doc.save('sample-file.pdf');
});</script>
</head>

<body>
<div id="content">
     <h3>Hello, this is a H3 tag</h3>

    <p>a pararaph</p>
</div>
<div id="editor"></div>
<button id="cmd" >generate PDF</button>
</body>
</html>

User avatar
emanipur
Joomla! Explorer
Joomla! Explorer
Posts: 392
Joined: Sat Jun 09, 2012 10:58 am
Location: Imphal
Contact:

Re: Custom button not working

Post by emanipur » Thu Jul 03, 2014 9:27 am

BUMP BUMP>.. anyone?

merryba
Joomla! Fledgling
Joomla! Fledgling
Posts: 3
Joined: Mon Dec 20, 2010 8:23 pm

Re: Custom button not working

Post by merryba » Mon Aug 17, 2015 7:27 pm

Were you able to solve it? I have the same issue.

harperlala
Joomla! Guru
Joomla! Guru
Posts: 697
Joined: Mon Aug 24, 2015 5:55 pm

Re: Custom button not working

Post by harperlala » Sun Sep 06, 2015 2:55 am

use firebug to check error or javascript conflict when you click button.


Locked

Return to “General Questions/New to Joomla! 2.5”