I've just started on my first AJAX project and I've just run into my first problem.
Basically I have a textarea field generated by ajax and it needs to submit that value to itself using post. I tried using a getElementById but it always returns null. Here is the code:
index.asp
<body onload=""javascript:showBookingNotes('" & request.QueryString("booking_id") & "','getBookingNotes.asp','view','0');">
<div id="notesresultsframe"><i>Loading notes...</i></div>
</body>
var xmlHttp
function stateChanged()
{
if (xmlHttp.readyState==4)
{
document.getElementById("notesresultsframe").innerHTML=xmlHttp.responseText;
}
}
function GetXmlHttpObject()
{
var xmlHttp=null;
try
{
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
}
catch (e)
{
// Internet Explorer
try
{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
}
return xmlHttp;
}
function showBookingNotes(qid, pagefile, action, noteid)
{
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
{
alert ("Your browser does not support AJAX!");
return;
}
alert(document.getElementById("note_description").value);
var url=pagefile;
url=url+"?q="+qid;
url=url+"&a="+action;
url=url+"¬eid="+noteid;
url=url+"&sid="+Math.random();
xmlHttp.onreadystatechange=stateChanged;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}
getBookingNotes.asp
<script src="../global/includes/ajax.js"></script>
<%
response.expires=-1
if request.querystring("a") = "add" then
MyConn.execute(somesqlcode)
end if
if request.querystring(a) = "delete" then
MyConn.execute("somesqlcode")
end if
set rsSetup = Server.CreateObject("ADODB.Recordset")
notesall = somesqlcode
rsSetup.open notesall, MyConn, 3, 3
SetupRecordCount = rsSetup.recordcount
if SetupRecordCount > 0 then
notesdata = rsSetup.getrows
notesnumcols = ubound(notesdata,1)
notesnumrows = ubound(notesdata,2)
end if
rsSetup.close
response.write "<table cellpadding=""0"" cellspacing=""0"" border=""0"">"
if SetupRecordCount > 0 then
for i = 0 to notesnumrows
response.write "<tr><td colspan=""2"" class=""notedescription"">" & i+1 & ". " & left(notesdata(1, i), 50) & "...</td></tr><tr><td class=""noteinfo"">" & notesdata(3, i) & " " & notesdata(2, i) & "<br />" & FormatDateTime(notesdata(4, i), 1) & "</td><td class=""noteinfo""><img src=""cross_small.png"" style=""cursor:pointer;"" onclick=""javascript:showBookingNotes('" & request.QueryString("booking_id") & "','getBookingNotes.asp', 'delete', '" & notesdata(0, i) & "');"" /></td></tr>"
next
else
response.write "<tr><td colspan=""2""></td></tr>"
end if
response.write "<tr><td colspan=""2""><textarea id=""note_description"" style=""border:0px;width:188px;height:60px;font-size:10px;font-family:arial;color:#cccccc;"">TYPE YOUR NOTE HERE</textarea></td></tr>"
response.write "<tr><td colspan=""2"" align=""right""><img src=""acformaddnotebutton.gif"" style=""margin:0px;padding:0px;margin-top:-2px;cursor:pointer;"" onclick=""javascript:showBookingNotes('" & request.QueryString("booking_id") & "','getBookingNotes.asp', 'add', '0');"" /></td></tr>"
response.write "</table>"
if SetupRecordCount > 0 then
erase notesdata
end if
%>