0

I am using kottke.org's old JAH example to return some html to a div in a webpage. The code works fine if I use static text. However I need to get the value of a field to add to the string that is getting passed as the parameter to the function.

var xmlhttp=false;
/*@cc_on @*/
/*@if (@_jscript_version >= 5)
try {
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
} catch (E) {
xmlhttp = false;
}
}
@end @*/

if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
xmlhttp = new XMLHttpRequest();
}

function getMyHTML(serverPage, objID) {
var obj = document.getElementById(objID);
xmlhttp.open("GET", serverPage);
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
obj.innerHTML = xmlhttp.responseText;
}
}
xmlhttp.send(null);
}

And on the page....

<a href="javascript://" onclick="getMyHTML('/WStepsDE?open&category="+document.getElementById('Employee').value;+"','goeshere')">Change it!</a></p>
<div id ="goeshere">Hey, this text will be replaced.</div>

It fails (with the help of Firebug) with the getMyHTML call where I try to get the value of Employee to include in the first parameter. The error is "Unterminated string literal". Thx in advance for your help.

1
  • You should mark one of these as the correct answer so people in the future will know that it worked.
    – Seph
    Mar 15, 2010 at 2:24

2 Answers 2

1

You're quotes are wrong. You can't nest the double-quotes inside the single-quotes. Try something like this:

<a href="javascript://" onclick="getMyHTML('/WStepsDE?open&category='+document.getElementById('Employee').value,'goeshere')">Change it!</a></p>
0

You've mixed the quotation marks in your onclick handler. You can rewrite it as a separate function correct them in the following manner:

<a href="javascript://" onclick="getMyHTML('/WStepsDE?open&category='+document.getElementById('Employee').value,'goeshere')">Change it!</a>
1
  • Thank you both.. That works great. I have another error now but I think it should be something easy. Thanks again!
    – Gerry S
    Mar 15, 2010 at 1:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.