I am pretty new to ASP, I know VBScript reasonably well though. What I am trying to do is create a website with 2 frames. In the top frame, it asks for a year (from a selection box) and a week number (from a selection box). It should then display the dates relating to the selection and a button to process the request. When the button is clicked the bottom form then processes a SQL query based on the selection in the top frame and displays the info.
Now, my problem is when it comes to understanding ASP. With ASP, all the code is processed then the output is sent to the browser. How do you update variables or even pass them to other frames when the code has already processed?
I just need some pointers on the way forward to accomplishing the above.
Thanks
First off, don't use frames: they're annoying, ugly, and outmoded.
You can do something like this in asp, but it's going to require a round trip (or two) to the server.
The basic outline of the page (let's call it thispage.asp) would be something like
<html><head>[head stuff]
<%
dim yr, wk, i
yr = request.form("Year")
wk = request.form("Week")
'- if you use form method='get', then use request.querystring("Year")
if not isnumeric(yr) then
yr = Year(date) 'or whatever else you want to use as a default
else
yr = CInt(yr)
end if
'similar validation for wk
%>
</head>
<body>
<form method="post" action="thispage.asp">
<select name="Year" size="1">
<%
for i = Year(Date) - 2 to Year(Date) + 2
response.write "<option value='" & i & "'"
if i = yr then response.write " selected"
response.write ">" & i & "</option>"
next
%>
</select> [similar code for week or date or whatever]
<input type="submit">
</form>
<%
If yr <> "" and wk <> "" Then
'- look up stuff in database and output the desired data
'- (this part will be much longer than this)
Else
Response.Write "<p>Please make your selections above.</p>"
End If
%>
</body></html>
If you need to output form fields that are dependent on the user's initial year & week selections, then you're going to need more than one trip to the server, but it's still the same idea: set up the variables you're going to need, see if they have values, write out the form, and then if all the necessary variables have all the necessary values, then you can do your output stuff.
Related
I have a checkbox
<td><strong>Online Ordering: </strong></td>
<td><input type="checkbox" name="OnlineOrdering" value="<%=OnlineOrdering%>" <% if OnlineOrdering = True then response.write "checked='Checked'" end if %>/></td>
How do i capture whether the checkbox is checked or unchecked when form is submitted?
OnlineOrdering = request.form("OnlineOrdering")
this does not work?
This should assign a true/false to the variable OnlineOrdering:
If Request.ServerVariables("REQUEST_METHOD") = "POST" Then
OnlineOrdering = (Request.Form("OnlineOrdering") <> "")
End If
I found this post because I was trying to solve the same problem. I have a solution that seems to work well.
In the HTML form, create dynamically generated checkboxes. The value of this_box_id used below can be any unique number. In my case it was the primary key (autonumber) for that question from the SQL Database . Dynamically generated the check boxes with an associated hidden field:
<input type="hidden" name="check_box_indicator" value="<%=this_box_id%>">
<input type="checkbox" name="box_id<%=this_email_selection_id%>"
value="<%=this_box_id%>">
When asp returns the values for this, it will return multiple values for check_box_indicator. Here's a sample query string snippet:
...&check_box_indicator=78&box_id78=78&check_box_indicator=98&check_box...
On the next page, ASP will read through the form data. It will find EVERY check_box_indicator and it's value. That value can be used to check the value of the associated checkbox. If that checkbox comes back, it was checked, if it doesn't you will know that it wasn't checked. In the sample above, checkbox 78 was checked and so the box_id78 value was passed, while checkbox 98 was not and box_id98 was not sent. Here's the code to use this.
For Each this_box_id In Request.Form("check_box_indicator") 'check EVERY box'
box_state = Request.Form("box_id"&this_box_id) 'collect passed values only'
if box_state > 0 then
store_value = "y"
else
store_value = "n"
end if
' you now have the this_box_id number identifying this item in the DB, '
' the value of the check box, if it was passed '
' and a definite y or n value '
Next
With the example querystring, you will get 78 y, 98 n
I'd like to know what is the exact code for dynamic variable from link and have it set via conditions of If and If else.
let say i have link of default.asp?variable=value&string=number
how can i get this into my page with coding it in conditional term. (not sure if my code is correct)
<%
DIM value = something
If blah-blah then
[asp code here]
else if blah-blah then
[another asp code here]
end if
%>
i have to match a dynamic value on If and Else If, something like that.
thanks in advance...
I'm going to assume your question is about ASP classic and that you're going to handle:
default.asp?cmd=add&x=5&y=4
default.asp?cmd=mult&x=5&y=4
And, respectively, you want the outputs to be
Answer is 9
Answer is 20
The ASP for that would be something like:
<html>
<head>
<title>simple asp</title>
</head>
<body>
<%
Dim cmd, x, y
cmd = Request.QueryString("cmd")
x = CDbl(Request.QueryString("x"))
y = CDbl(Request.QueryString("y"))
Select Case cmd
Case "add"
Response.Write("Answer is " & (x + y))
Case "mult"
Response.Write("Answer is " & (x * y))
Case Else
Response.Write("Please supply a valid cmd")
End Select
%>
</body>
</html>
get idea from this line of codes
<%
Set udrmcatgry=TheDB.Execute("SELECT * FROM rmcatgry ORDER BY sl asc")
Do while Not udrmcatgry.eof=true
myqsl=udrmcatgry("sl")
TheDB.Execute "Update `rmcatgry` set catnme`='"&request.form(""+myqsl+"")&"' where sl='"&myqsl&"' "
udrmcatgry.MoveNext
Loop
%>
This code was working up until today now I keep getting the buffer exceeded error. I'm positive there is a much better way to do this but I have no idea how.
What I'm trying to do is display any entry from the current date to two weeks out. Users can enter any date within that two week period and the table will fill the spaces in between or after with a default "GREEN" span. I had it working until today. I haven't touched it in three weeks and I have no idea what happened. I'm a lowly graphic designer who's bosses don't know the difference between html/css and asp/sql driven applications. Please help before I go insane...
<div class="cond_holder">
<div class="dir_name">PEDS CARDIOLOGY</div>
<%
Dim this_day_peds_cardio
this_day_peds_cardio = Date
Dim Conditions_peds_cardio
Dim Conditions_peds_cardio_cmd
Dim Conditions_peds_cardio_numRows
Set Conditions_peds_cardio_cmd = Server.CreateObject ("ADODB.Command")
Conditions_peds_cardio_cmd.ActiveConnection = MM_webdbs_STRING
Conditions_peds_cardio_cmd.CommandText = "SELECT * FROM dbo.ryg_conditions WHERE aoc='1' AND Day >= DATEADD(dd, DATEDIFF(dd, 0, GETDATE()), 0) ORDER BY aoc ASC, Day ASC"
Conditions_peds_cardio_cmd.Prepared = true
Set Conditions_peds_cardio = Conditions_peds_cardio_cmd.Execute
Conditions_peds_cardio_numRows = 0
Dim Repeat_peds_cardio__numRows
Dim Repeat_peds_cardio__index
Repeat_peds_cardio__numRows = 14
Repeat_peds_cardio__index = 0
Conditions_peds_cardio_numRows = Conditions_peds_cardio_numRows + Repeat_peds_cardio__numRows
While ((Repeat_peds_cardio__numRows <> 0) AND (NOT Conditions_peds_cardio.EOF))
If DateDiff("d", (Conditions_peds_cardio.Fields.Item("Day").Value), this_day_peds_cardio)=0 Then
%>
<span class="daily_condition <%=(Conditions_peds_cardio.Fields.Item("ryg").Value)%>">
<span style="display: none;"><%=(Conditions_peds_cardio.Fields.Item("aoc").Value)%></span>
<%=(Conditions_peds_cardio.Fields.Item("ryg").Value)%>
<span class="reason"><%=(Conditions_peds_cardio.Fields.Item("reasoning").Value)%></span>
</span><!-- /.daily_condtion -->
<%
this_day_peds_cardio = DateAdd("d", 1, this_day_peds_cardio)
Else
While DateDiff("d", (Conditions_peds_cardio.Fields.Item("Day").Value), this_day_peds_cardio)<>0
%>
<span class="daily_condition GREEN">GREEN</span><!-- SPACER -->
<%
this_day_peds_cardio = DateAdd("d", 1, this_day_peds_cardio)
Wend
%>
<span class="daily_condition <%=(Conditions_peds_cardio.Fields.Item("ryg").Value)%>">
<span style="display: none;"><%=(Conditions_peds_cardio.Fields.Item("aoc").Value)%></span>
<%=(Conditions_peds_cardio.Fields.Item("ryg").Value)%>
<span class="reason"><%=(Conditions_peds_cardio.Fields.Item("reasoning").Value)%></span>
</span><!-- /.daily_condtion -->
<%
this_day_peds_cardio = DateAdd("d", 1, this_day_peds_cardio)
End if
Repeat_peds_cardio__index=Repeat_peds_cardio__index+1
Repeat_peds_cardio__numRows=Repeat_peds_cardio__numRows-1
Conditions_peds_cardio.MoveNext()
Wend
While loop_ctr_peds_cardio < 14
%>
<span class="daily_condition GREEN">GREEN</span><!-- FILLER -->
<%
loop_ctr_peds_cardio = loop_ctr_peds_cardio +1
Wend
%>
</div><!-- /#cond_holder -->
When I read your source code, I came up with two thinks:
You use too many script tags (<% %>), even to seperate vbscript code. This overusing makes it hard to read and understand your code. I had to paste your source code into Notepad++ to tidy up and reading your code.
You didn't use a recordset for the first while query. If you want loop through a result of a Selectquery use the recordset object. It is more convinence to handle and prevents some general errors. Does the using of a recordset eleminate your error?
To your problem:
Do you use an IIS6.0 or higher? If so then following ideas could help (I got it from a german! site of Microsoft, posted in stackoverflow.com (see here). The idears are:
Using Response.Flush()
Turn the Response.Buffer off on the page, or on the entire site.
Response.Buffer = False at the top of the page before any ASP code.
Increase the size of the buffer (see the link on 'see here' position).
Decrase the size of your response.
The reason your response buffer is overflowing is because you have more data to show now. The quickest way to get it sorted should be to issue a Response.Flush every couple of rows or so (depending on how big the response buffer is) inside your while loop. Turning off the response buffer will almost always result in the page taking longer to render, especially if you have lots of context switches like you do.
Hi I've run into a really annoying problem, I'm trying to set the value of a hidden input to a comma seperated list taken from a database but in pure CSV format it won't set the value.
The input tag and ul tag looks like this (I am aware of asp:hiddenfield and it's value property but I'm not using it as I still have this issue):
<ul id="keywords" runat="server">
</ul>
<input type="hidden" id="keywordsBox" runat="server" />
The code I'm using to populate it is:
'connection strings and all that stuff is set up and using a SqlDataReader to sort through results
while result.Read()
keywordsBox.Attribute.Add("value", result.Item("keywords"))
keywords.innerHTML = "<li>" & Replace(result.Item("keywords"),",","</li><li>") & "</li>"
End while
This will populate the li tags but will not populate the value for the input, I've tried using the replace function on the list for the value but it only works if I remove the commas or put other characters infront of them. I've also tried replacing it with the HTML code for a comma but just prints the HTML code out.
Has anybody else ran into this at all? How'd you fix it?
Try the below code, this will solve your problem:
dim hValue as string =""
while result.Read()
hValue += result.Item("keywords")
keywords.innerHTML = "<li>" & Replace(result.Item("keywords"),",","</li><li>") & "</li>"
End while
keywordsBox.Attribute.Add("value", hValue )
i want to make an asp query so that an event is shown when it's date is greater or equal.
here's the code so far, but it doesn't work.
<%
strDateNow = date
strDateEvent = "30.05.2011"
%>
<% if strDateEvent >= strDateNow then %>
HELLO
<% end if %>
thanks for any help,
alex
I assume this is VBScript + Classic ASP rather than .net?
strDateEvent is a string so the >= is not comparing dates.
To compare against strDateNow which is a date despite its name, you need to convert strDateEvent to a date in order to compare:
If CDate(strDateEvent) >= strDateNow Then
If this fails with a type error then the format "30.05.2011" cannot be converted so use another; "10/04/2011" (ensuring dmy order is appropriate for your locale)