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
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
"unterminated string literal" means that somewhere a string variable is opened by not closed properly, either because of un-escaped character in it, or a line break, or something like that.
To solve the "Unterminated string constant" error, make sure to enclose your strings in quotes consistently. String literals must be enclosed in single quotes, double quotes or backticks. When writing a multiline string use backticks.
A "string literal" is a sequence of characters from the source character set enclosed in double quotation marks (" "). String literals are used to represent a sequence of characters which, taken together, form a null-terminated string. You must always prefix wide-string literals with the letter L.
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();
}
Just a suggestion: Change your line from:
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>'
to
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>";
I have replaced " with ' and viceversa.. This would probably remove your error.Hopefully.
NOTE: Since in comment you mentioned that $('report_excel') is actually you tableId the correct jquery way to access id is $("#report_excel").. Use #
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With