This is really out of my league and i could do with some help.
I am trying to check the database to see if a some text exists using a form.
I came across this coding and it is perfect for what i need. I have incorporated it into my web site and the problem I'm having is when i type in a sentence to be checked, the result after it has checked the database for an existing sentence, the result displayed is the same sentence but with all the spaces removed.
I'm no good with AJAX so any help in trying to solve this issue would be greatly appreciated.
<script type="text/javascript">
//If our user enters data in the username input, then we need to enable our button
function OnChangedQuestion()
{
if(document.form1.newuserid.value == "")
{
document.form1.btnCheckAvailability.disabled = true;
}
else
{
document.form1.btnCheckAvailability.disabled = false;
}
}
function OnCheckAvailability()
{
if(window.XMLHttpRequest)
{
oRequest = new XMLHttpRequest();
}
else if(window.ActiveXObject)
{
oRequest = new ActiveXObject("Microsoft.XMLHTTP");
}
oRequest.open("POST", "checkdatabase.asp", true);
oRequest.onreadystatechange = UpdateCheckAvailability;
oRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
oRequest.send("strCmd=availability&strQuestion=" + document.form1.newuserid.value);
}
function UpdateCheckAvailability()
{
if(oRequest.readyState == 4)
{
if(oRequest.status == 200)
{
document.getElementById("Available").innerHTML = oRequest.responseText;
}
else
{
document.getElementById("Available").innerHTML = "Error";
}
}
}
</script>
ASP CODE
Code:
<%
' Form Variables
dim strCmd
dim strQuestion
strCmd = trim(Request.Form("strCmd").Item)
Session("strQuestion") = trim(Request.Form("strQuestion").Item)
If Session("strQuestion") ="The cat ran up the hill" Then
Response.Write("Error This Record Exists.")
else
Response.Write("Checked!!!!")
end if
Response.end
%>
When i type in "The cat ran up the hill" the result i get back when i click on check database is "Thecatranupthehill"
Still the same problem when i type "The cat ran up the hill", the responce i get back after it has been checked in the database is "Thecatranupthehill".
Ok, still pursuing with this and i've now found that the main problem could be this.
If i enter "the%20cat%20ran%20up%20the%20hill" in the input field. It returns i get back from the database search is "The cat ran up the hill" which is what i want. Is this something to do with Javascript?
Bookmarks