Search code examples
javascripthtmlruby-on-rails-3prototypejs

SyntaxError: unterminated string literal


I have the below code in which i am getting the strange error.

   function export_to_excel()

     {

    results_html = $('report_excel').innerHTML;
    results_html = '<html><body><table  align="center" cellspacing="0" cellpadding="0" width="100%"><tr><td colspan="9"><b>Employee Salary Register </b></td></tr><tr><td colspan="9"></td></tr>' + results_html + '</table></body></html>';
    var input = new Element('input', {
        'type': 'hidden',
        'name': 'results[html]',
        'value': results_html
    });
    var form = new Element('form', {
        'method': 'post',
        'name': 'Employee Salary Register',
        'action': "html_to_excel"
    });
    form.insert(input);
    document.body.appendChild(form);
    form.submit();
}

The error is occurring at this line

results_html = '<html><body><table  align="center" cellspacing="0" cellpadding="0" width="100%"><tr><td colspan="9"><b>Employee Salary Register </b></td></tr><tr><td colspan="9"></td></tr>' + results_html + '</table></body></html>';

EDIT:

The error is showing in the console of Firebug pointing to that line.I just attached a Screenshot

Screenshot

There you can see,under the Two Buttons(print and Export),the code is appearing on the screen.Those code lines are part of the function export_to_excel()

It does works perfectly in my Local Server too. I'm Using PrototypeJS and I'm sorry for the Misleading and sorry for the delay too.

Any help will be greatly appreciated


Solution

  • I have implemented your code below, and it works well First Define your id/class first in this line results_html = $('report_excel').innerHTML;

    function export_to_excel(){
    
        results_html = $('report_excel').innerHTML;
        results_html = "<html><body><table  align='center' cellspacing='0' cellpadding='0' width='100%'><tr><td colspan='9'><b>Employee Salary Register </b></td></tr><tr><td colspan='9'></td></tr>" + results_html + "</table></body></html>";
        var input = new Element('input', {
            'type': 'hidden',
            'name': 'results[html]',
            'value': results_html
        });
        var form = new Element('form', {
            'method': 'post',
            'name': 'Employee Salary Register',
            'action': "html_to_excel"
        });
        form.insert(input);
        document.body.appendChild(form);
        form.submit();
    }