Jump to content

ASP / AJAX search between 2 dates


toga38
 Share

Recommended Posts

New to web pagesI am trying to search a database between 2 dates (I havent got as fare as accessing the Database yet but I have included the ASP code I intend to use see below).The problem I have at the moment is sending 2 variables "str" & "str1" read in from text boxes (see code below). Could any help with the problem of sending the 2 variables or would the only way be to use a form?Html, java and ajax code:<html><head><script type="text/javascript">function showTape(str, str1){if (str=="" || str==null) { alert("Enter start date"); document.getElementById("date").innerHTML=""; return false; }if (str1=="" || str1==null) { alert("Enter end date"); document.getElementById("date1").innerHTML=""; return false; }xmlhttp=new XMLHttpRequest();xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4 && xmlhttp.status==200) { document.getElementById("txtdate").innerHTML=xmlhttp.responseText; } }xmlhttp.open("post","getTape.asp?q="+str,true);xmlhttp.send(str, str1);}</script></head<body><br />Start date: <br /><input type="text" name="date" id="date"/> <br /><br />End date: <br /><input type="text" name="date1" id="date1"/> <br/><button type="button" onclick="showTape(date.value, date1.value)">Save </button><br /><br /><div id="txtTape">Info will be listed here...</div><br /></body></html>Asp code:<%response.expires=-1str = request.querystring("str")str1 = request.querystring("str1") Set oConnection = Server.CreateObject("ADODB.Connection")oConnection.Open "Driver={SQL Server};Server=itdxp34;Database=KNtest;Trusted_Connection=Yes;" ''Search between datessql="SELECT * FROM tapeUsed WHERE saveDate BETWEEN str AND str1"sql=sql & "'" & request.querystring("q") & "'"set rs = oConnection.Execute(sql) response.write("<table>")do until rs.EOF for each x in rs.Fields 'if trim(rs.fields(0).value) = "" then 'response.write("Null data field") 'else response.write("<td>" & trim(rs.fields(2).value) & " " & trim(rs.fields(0).value) & " " & trim(rs.fields(1).value) &"</td></tr>") 'end if next rs.MoveNextloop response.write("</table>")%>

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...