jhob
05-14-2007, 12:28 PM
I have the bit of code below that looks simple enough but for some reason I'm getting an 'unterminated string constant' error on the </script> line and can't for the life of me figure out why as the string appears to be well formed. It's obviously not well formed but I've been staring at this for so long now that I can't see the wood for the trees and I'd appreciate a second of eyes to look over it and see if they can see where I've gone wrong.
<script language="javascript">
var strcatrow = '<script type=\"text/javascript\">\n' +
'var names = new DynamicOptionList();\n' +
'names.addDependentFields(\'prodcat1a\',\'prodcat2a\');\n' +
'names.forValue(\"1\").addOptionsTextValue(\'mingle mingle mangle\', \'17\', \'test 2 likes mince\', \'15\', \'test 3 is best\', \'16\', \'testy testy ra ra ra\', \'14\');\n' +
'names.forValue(\"2\").addOptionsTextValue(\'Goldfish\', \'6\', \'Piranha\', \'5\', \'Shark\', \'7\');\n' +
'names.forValue(\"3\").addOptionsTextValue(\'Dog\', \'9\', \'Human\', \'8\', \'Seal\', \'10\');\n' +
'names.forValue(\"4\").addOptionsTextValue(\'Boulder\', \'13\', \'Gravel\', \'12\', \'Stone\', \'11\');\n' +
'</script>\n' +
'<select name=\"prodcat1a\" class=\"formstyling\" id=\"prodcat1a\">\n' +
'<option value=\"\"></option>\n' +
'<option value=\"2\">Fishes</option>\n' +
'<option value=\"3\">Mammals</option>\n' +
'<option value=\"4\">Rocks</option>\n' +
'<option value=\"1\">Test Category 1</option>\n' +
'</select>\n' +
'<select name=\"prodcat2a\"><script type=\"text/javascript\">names.printOptions(\"prodcat2a\");</script></select>\n' +
'<input name=\"test\" id=\"test\" type=\"text\" onfocus=\"javascript\:document.getElementById(\"test\").value = document.getElementById(\"prodcat2a\").value\"/>\n';
document.write(strcatrow);
</script>
Thanks in advance for any replies, I'm beginning to tear my hair out over this one!
John
<script language="javascript">
var strcatrow = '<script type=\"text/javascript\">\n' +
'var names = new DynamicOptionList();\n' +
'names.addDependentFields(\'prodcat1a\',\'prodcat2a\');\n' +
'names.forValue(\"1\").addOptionsTextValue(\'mingle mingle mangle\', \'17\', \'test 2 likes mince\', \'15\', \'test 3 is best\', \'16\', \'testy testy ra ra ra\', \'14\');\n' +
'names.forValue(\"2\").addOptionsTextValue(\'Goldfish\', \'6\', \'Piranha\', \'5\', \'Shark\', \'7\');\n' +
'names.forValue(\"3\").addOptionsTextValue(\'Dog\', \'9\', \'Human\', \'8\', \'Seal\', \'10\');\n' +
'names.forValue(\"4\").addOptionsTextValue(\'Boulder\', \'13\', \'Gravel\', \'12\', \'Stone\', \'11\');\n' +
'</script>\n' +
'<select name=\"prodcat1a\" class=\"formstyling\" id=\"prodcat1a\">\n' +
'<option value=\"\"></option>\n' +
'<option value=\"2\">Fishes</option>\n' +
'<option value=\"3\">Mammals</option>\n' +
'<option value=\"4\">Rocks</option>\n' +
'<option value=\"1\">Test Category 1</option>\n' +
'</select>\n' +
'<select name=\"prodcat2a\"><script type=\"text/javascript\">names.printOptions(\"prodcat2a\");</script></select>\n' +
'<input name=\"test\" id=\"test\" type=\"text\" onfocus=\"javascript\:document.getElementById(\"test\").value = document.getElementById(\"prodcat2a\").value\"/>\n';
document.write(strcatrow);
</script>
Thanks in advance for any replies, I'm beginning to tear my hair out over this one!
John