cubicalmonkey
asked on
unterminated string constant on in IE for complex function
Hello,
I'm attempting to get this code to work in IE.
The script I have below works fine in Firefox but doesn't work in IE.
Does anyone have any suggestions to make this work in IE?
The error I get is "ERROR: unterminated string constant"
The error is on line 55 which is the line below starting with inputs[i].onclick.
var texts = new Array();
function spanify()
{
//addField();
var inputs = document.getElementsByTagN ame('input ');
for(var i=0; i<inputs.length; i++)
{
var curnode = inputs[i].nextSibling;
var newSpan = document.createElement('sp an');
while(curnode != null)
{
if(curnode.tagName != null && curnode.tagName.match(/inp ut/i))
{
curnode = null;
}
else
{
newSpan.appendChild(curnod e.cloneNod e(true));
curnode = curnode.nextSibling;
}
}
inputs[i].onclick = new Function("var answers = ('" + megatrim(newSpan.innerHTML .toString( )) + "'); popinframe(answers); doSubmit();");
}
}
I'm attempting to get this code to work in IE.
The script I have below works fine in Firefox but doesn't work in IE.
Does anyone have any suggestions to make this work in IE?
The error I get is "ERROR: unterminated string constant"
The error is on line 55 which is the line below starting with inputs[i].onclick.
var texts = new Array();
function spanify()
{
//addField();
var inputs = document.getElementsByTagN
for(var i=0; i<inputs.length; i++)
{
var curnode = inputs[i].nextSibling;
var newSpan = document.createElement('sp
while(curnode != null)
{
if(curnode.tagName != null && curnode.tagName.match(/inp
{
curnode = null;
}
else
{
newSpan.appendChild(curnod
curnode = curnode.nextSibling;
}
}
inputs[i].onclick = new Function("var answers = ('" + megatrim(newSpan.innerHTML
}
}
getElementsByTagName isn't valid in IE6. Try something like this instead:
http://www.thescripts.com/forum/thread153313.html
http://www.thescripts.com/forum/thread153313.html
Or, use getElementById
ASKER
Basicinstinct help me with the megtrim function.
The link below explains what's happening in the code.
https://www.experts-exchange.com/questions/22842770/How-to-parse-text-between-HTML-tags-and-set-to-variable-value.html
Thanks for the advise, unfortunately I'm unable to use the getElementById option however, I'll check out the link jmang posted.
The link below explains what's happening in the code.
https://www.experts-exchange.com/questions/22842770/How-to-parse-text-between-HTML-tags-and-set-to-variable-value.html
Thanks for the advise, unfortunately I'm unable to use the getElementById option however, I'll check out the link jmang posted.
Why can't you use getElementById?
ASKER
The radio buttons on the form is dynamically generated by a java applet which I don't have any control over nor know anything about.
https://www.experts-exchange.com/questions/22842770/How-to-parse-text-between-HTML-tags-and-set-to-variable-value.html
Once the page is written, I'm adding some javascript to the <input tags in order for the form to return which option is selected.
I suppose this explanation would make more sense if you check out my related question in the link provided.
https://www.experts-exchange.com/questions/22842770/How-to-parse-text-between-HTML-tags-and-set-to-variable-value.html
Once the page is written, I'm adding some javascript to the <input tags in order for the form to return which option is selected.
I suppose this explanation would make more sense if you check out my related question in the link provided.
Ok, well technically if there are form controls on the page, then you can navigate through the DOM to get at the inputs. Granted, this is a hassle, but if that's not feasible, see if you can get that example I sent to work.
Thanks for the clarification.
Thanks for the clarification.
HI,
The unterminated string constant could also happen if there are any single quotes (') or double quotes(") as a part of the innerHTML value. If so we need to handle those cases as well.
If you want to maintain the quotes then you can use the following
function megatrim(str) {
str = str.replace(/'/g, "\\\'");
str = str.replace(/"/g, "\\\"");
atr = str.replace(/^\s+|\s+$|\n/ g, '');
return str;
}
If you do not want to preserve the quotes, you can try this.
function megatrim(str) {
str = str.replace(/'/g, "");
str = str.replace(/"/g, "");
atr = str.replace(/^\s+|\s+$|\n/ g, '');
return str;
}
If you are still getting the same error, can you please post what is the value of the innerHTML that you are getting?
Hope this is useful.
arunrs
Hope this is useful.
The unterminated string constant could also happen if there are any single quotes (') or double quotes(") as a part of the innerHTML value. If so we need to handle those cases as well.
If you want to maintain the quotes then you can use the following
function megatrim(str) {
str = str.replace(/'/g, "\\\'");
str = str.replace(/"/g, "\\\"");
atr = str.replace(/^\s+|\s+$|\n/
return str;
}
If you do not want to preserve the quotes, you can try this.
function megatrim(str) {
str = str.replace(/'/g, "");
str = str.replace(/"/g, "");
atr = str.replace(/^\s+|\s+$|\n/
return str;
}
If you are still getting the same error, can you please post what is the value of the innerHTML that you are getting?
Hope this is useful.
arunrs
Hope this is useful.
There was a small spell mistake in the code ..
Change
atr = str.replace(/^\s+|\s+$|\n/ g, '');
to
str = str.replace(/^\s+|\s+$|\n/ g, '');
arunrs
Change
atr = str.replace(/^\s+|\s+$|\n/
to
str = str.replace(/^\s+|\s+$|\n/
arunrs
ASKER
Arunrs,
Thank you for your suggestion.
I've replaced the existing megatrim function with your function however,
I'm still experiencing the same error in IE.
Worked great in Firefox, even firebug doesn't spit out any warnings ect...
As requested this is the data retrieved in innerHTML.
Again the content within the form is dynamically populated from a java applet.
The content changes based on which options are selected.
<FORM NAME=MYFORM id='MYFORM' METHOD=POST ACTION=advisor.jsp OnSubmit='doSubmit()'>
<INPUT TYPE=HIDDEN NAME=ROLLUP VALUE=0><p><br><b>Select the setup the customer having problems with </b></B><BR>
<INPUT TYPE=RADIO OnClick='doSubmit()' NAME=default_Q1_2_2136 VALUE=222085 >1 Computer directly connected to the modem<BR>
<INPUT TYPE=RADIO OnClick='doSubmit()' NAME=default_Q1_2_2136 VALUE=222086>1 Computer out of many having a problem connected through a router<BR>
<INPUT TYPE=RADIO OnClick='doSubmit()' NAME=default_Q1_2_2136 VALUE=222087>Are ALL computers connected through the router having a problem<P>
<INPUT TYPE=HIDDEN NAME=CompanyID VALUE=2><INPUT TYPE=HIDDEN NAME=RuleID VALUE=2136>
<INPUT TYPE=HIDDEN NAME=SubRuleID VALUE=81926>
<INPUT TYPE=HIDDEN NAME=RuleControlID VALUE=2136>
<input type=hidden name=Path value=http://web01.ad.net:8080/advisor/pages/templates/>
<input type=hidden name=History value=''>
<input type=hidden name=Current value=''>
<input type=hidden name=Template value=imtg12.html>
</FORM>
Thank you for your suggestion.
I've replaced the existing megatrim function with your function however,
I'm still experiencing the same error in IE.
Worked great in Firefox, even firebug doesn't spit out any warnings ect...
As requested this is the data retrieved in innerHTML.
Again the content within the form is dynamically populated from a java applet.
The content changes based on which options are selected.
<FORM NAME=MYFORM id='MYFORM' METHOD=POST ACTION=advisor.jsp OnSubmit='doSubmit()'>
<INPUT TYPE=HIDDEN NAME=ROLLUP VALUE=0><p><br><b>Select the setup the customer having problems with </b></B><BR>
<INPUT TYPE=RADIO OnClick='doSubmit()' NAME=default_Q1_2_2136 VALUE=222085 >1 Computer directly connected to the modem<BR>
<INPUT TYPE=RADIO OnClick='doSubmit()' NAME=default_Q1_2_2136 VALUE=222086>1 Computer out of many having a problem connected through a router<BR>
<INPUT TYPE=RADIO OnClick='doSubmit()' NAME=default_Q1_2_2136 VALUE=222087>Are ALL computers connected through the router having a problem<P>
<INPUT TYPE=HIDDEN NAME=CompanyID VALUE=2><INPUT TYPE=HIDDEN NAME=RuleID VALUE=2136>
<INPUT TYPE=HIDDEN NAME=SubRuleID VALUE=81926>
<INPUT TYPE=HIDDEN NAME=RuleControlID VALUE=2136>
<input type=hidden name=Path value=http://web01.ad.net:8080/advisor/pages/templates/>
<input type=hidden name=History value=''>
<input type=hidden name=Current value=''>
<input type=hidden name=Template value=imtg12.html>
</FORM>
ASKER
Strange, when I escape the " in the line of code shown below, IE is happy. No Errors.
But when I call the fucntion popinframe(answers);
Which esentially just displays when ever was after the <input> tag, it shows +megatrim(newSpan.innerHTM L.toString ())+ instead of the correct data that shows in Firefox.
inputs[i].onclick = new Function("var answers=('\"+megatrim(newS pan.innerH TML.toStri ng())+\"') ;popinfram e(answers) ;doSubmit( );");
But when I call the fucntion popinframe(answers);
Which esentially just displays when ever was after the <input> tag, it shows +megatrim(newSpan.innerHTM
inputs[i].onclick = new Function("var answers=('\"+megatrim(newS
ASKER
Anyone have any other Ideas?
Although I'm only a novice at best, I wasn't aware getElementsByTagName isn't valid in IE6.
I thought I've used that method some place, maybe not...
Although I'm only a novice at best, I wasn't aware getElementsByTagName isn't valid in IE6.
I thought I've used that method some place, maybe not...
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
I guess you can use getElementsByTagName in IE 6.0. It should not create any problem because I have used it in my code.
arunrs
arunrs
ASKER
arunrs,
Thank you very much!
That worked to resolve my issue.
I cant thank you enough!
Thank you very much!
That worked to resolve my issue.
I cant thank you enough!
Not a problem. Sorry I could not reply back immediately after your reply with the innerHTML content as I was bit busy with my work.
arunrs
arunrs
Sometimes, there might be \n character that need to be replaced which might cause this problem.
try adding this inside the megatrim
megatrim (inputStr) {
...
...
inputStr = inputStr.replace(/\n/g, " "); // This will replace all the \n character with space.
}
Hope this is useful.
arunrs