Hi everyone,
a bit stumped with this but Iam sure it is probably simple if you work with javascript a lot.
I have written a peice of code to carry out a function on my website which basically submits the variables from an input to an asp form and then displays a message to say thanks for your comments without refreshing the active page.
Only problem is I know javascript doesnt like it if there are & symbols or ' symbols in the input box when it is sending as it takes them to be code rather than text.
So I added the following to my function
<!--**** start of feedback code **** -->
<script type="text/javascript">
function sendRequest(feedback,commentDivId)
{
var pageLocation=window.location.pathname;
var pageLocation = pageLocation.substring(pageLocation.lastIndexOf('/') + 1);
var strFeedback = feedback.value;
strFeedback = strFeedback.replace("&","&");
strFeedback = strFeedback.replace("'","''");
if (feedback.value=='')
{
alert('Please enter your comments then submit.')
return false;
}
else
{
// create XML for HTTP POST
var oDomDoc = Sarissa.getDomDocument();
var xmlString = "<request><feedback>"+strFeedback+"</feedback><pagelocation>"+pageLocation+"</pagelocation></request>";
oDomDoc = (new DOMParser()).parseFromString(xmlString, "text/xml");
// debug-target: popup XML request for debugging
// create XMLHTTPRequest object and POST xml
var xmlhttp = new XMLHttpRequest();
xmlhttp.open("POST", " false);
xmlhttp.send(oDomDoc);
// enable following line
var oDomResultDoc = xmlhttp.responseXML;
// debug-target display xml response result
//alert("XML HTTP Response: "+Sarissa.serialize(oDomResultDoc));
// initialize result
var elResult = oDomResultDoc.getElementsByTagName("return");
var returnValue = elResult[0].getElementsByTagName("feedbackentered")[0].firstChild.nodeValue;
if (returnValue=="true")
{
document.getElementById('customerFeedbackRight').innerHTML=' '
commentDivId.innerHTML = '<p class="text" style="width=559px; float:left; margin-top:7px;">Thank you for your comments</p>';
}
else
commentDivId.innerHTML = '<p style="width=559px; float:left; margin-top:7px;">There is problem.</p>';
}
}
</script>
<!--**** end of feedback code **** -->
Now if I type
hello & welcome
it will work fine
but if i type hello & welcome & hello
it will not submit! How can i change the replacement string to cover multiple characters?
Thanks a lot
a bit stumped with this but Iam sure it is probably simple if you work with javascript a lot.
I have written a peice of code to carry out a function on my website which basically submits the variables from an input to an asp form and then displays a message to say thanks for your comments without refreshing the active page.
Only problem is I know javascript doesnt like it if there are & symbols or ' symbols in the input box when it is sending as it takes them to be code rather than text.
So I added the following to my function
<!--**** start of feedback code **** -->
<script type="text/javascript">
function sendRequest(feedback,commentDivId)
{
var pageLocation=window.location.pathname;
var pageLocation = pageLocation.substring(pageLocation.lastIndexOf('/') + 1);
var strFeedback = feedback.value;
strFeedback = strFeedback.replace("&","&");
strFeedback = strFeedback.replace("'","''");
if (feedback.value=='')
{
alert('Please enter your comments then submit.')
return false;
}
else
{
// create XML for HTTP POST
var oDomDoc = Sarissa.getDomDocument();
var xmlString = "<request><feedback>"+strFeedback+"</feedback><pagelocation>"+pageLocation+"</pagelocation></request>";
oDomDoc = (new DOMParser()).parseFromString(xmlString, "text/xml");
// debug-target: popup XML request for debugging
// create XMLHTTPRequest object and POST xml
var xmlhttp = new XMLHttpRequest();
xmlhttp.open("POST", " false);
xmlhttp.send(oDomDoc);
// enable following line
var oDomResultDoc = xmlhttp.responseXML;
// debug-target display xml response result
//alert("XML HTTP Response: "+Sarissa.serialize(oDomResultDoc));
// initialize result
var elResult = oDomResultDoc.getElementsByTagName("return");
var returnValue = elResult[0].getElementsByTagName("feedbackentered")[0].firstChild.nodeValue;
if (returnValue=="true")
{
document.getElementById('customerFeedbackRight').innerHTML=' '
commentDivId.innerHTML = '<p class="text" style="width=559px; float:left; margin-top:7px;">Thank you for your comments</p>';
}
else
commentDivId.innerHTML = '<p style="width=559px; float:left; margin-top:7px;">There is problem.</p>';
}
}
</script>
<!--**** end of feedback code **** -->
Now if I type
hello & welcome
it will work fine
but if i type hello & welcome & hello
it will not submit! How can i change the replacement string to cover multiple characters?
Thanks a lot