Jump to content

ASP / AJAX search between 2 dates


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 post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...