Why <%if cars="Volvo" then Response.Write("checked")%> - asp-classic

I am kind a new to ASP and i see an example but can't figure out why using
<%if cars="Volvo" then Response.Write("checked")%>
Code:->
<!DOCTYPE html>
<html>
<%
dim cars
cars=Request.Form("cars")
%>
<body>
<form action="demo_radiob.asp" method="post">
<p>Please select your favorite car:</p>
<input type="radio" name="cars"
<%if cars="Volvo" then Response.Write("checked")%>
value="Volvo">Volvo</input>
<br>
<input type="radio" name="cars"
<%if cars="Saab" then Response.Write("checked")%>
value="Saab">Saab</input>
<br>
<input type="radio" name="cars"
<%if cars="BMW" then Response.Write("checked")%>
value="BMW">BMW</input>
<br><br>
<input type="submit" value="Submit" />
</form>
<%
if cars<>"" then
Response.Write("<p>Your favorite car is: " & cars & "</p>")
end if
%>
</body>
</html>
Any help would be appreciated

It is being used to make the radio button checked when output as HTML.
Here is more detailed explaination of the checked attribute - http://www.w3schools.com/tags/att_input_checked.asp
The response.write is printing out the string. Again here is a link to a more detailed explaination - http://www.w3schools.com/asp/met_write_response.asp
HTH
Wade

Related

Ftp using filezilla in asp.net

i have created this file in visual studio 2012 . The first page of survey works completely fine but when it re directs to display its showing '500 internal server error. The project has no compilation error . i am opening this file using filezilla can anyone please help me . its a simple program which fetches the value from survey.asp and displays the value in the next form in a tabular format.
------ survey.asp-----------------------------
<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<title>Survey Form</title>
</head>
<body>
<form method="post" action="display.asp">
<br/>
Please Enter Your Age <input type="text" name="first" value="<%=request("Age")%>"/> <br /> <br/>
Please Enter Your Salary $ <input type="text" name="sal" value="<%=request("salary")%>"/> <br /><br/>
What level of Education Have You Completed : <br/>
<input type="radio" name="radiobutton" value="<%=request("education")%>"/> Some High School <br />
<input type="radio" name="radiobutton" value="<%=request("education")%>"/> Completed high School <br />
<input type="radio" name="radiobutton" value="<%=request("education")%>"/>Some College Education <br />
<input type="radio" name="radiobutton" value="<%=request("education")%>"/> Completed a B.S Degree <br />
<input type="radio" name="radiobutton" value="<%=request("education")%>"/> Completed a Master Degree <br /> <br/>
<input type="submit" value="Send Survey" />
</form>
</body>
</html>
----------display.asp---------------------------------
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%
Age = request.form("first")
salary = request.form("sal")
education = request.form("radiobutton").ToString();
if age="" or salary="" or education="" then
%>
<html>
<head><title></title></head>
<body>
You must enter all the info
<form method="post " action="survey.asp">
<input type="hidden" name="age" value="<%=age%>" />
<input type="hidden" name="salary" value="<%=salary%>" />
<input type="hidden" name="education" value="<%=education%>" /> <br/>
<input type="submit" value="Return" />
</form>
</body>
</html>
<%
response.end
end if
%>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>Display Name</title>
</head>
<body>
You entered: <br />
<table>
<tr>
<td> <%=age%> </td>
<td> <%=salary%> </td>
<td> <%=education %> </td>
</tr>
</table>
<br />
</body>
</html>
This is classic asp with vbscript, not asp.net with C#. You don't get compilation errors with classic because it isn't compiled, it's interpreted at runtime.
You appear to have put a line of C# in display.asp - if you replace the line
education = request.form("radiobutton").ToString();
with
education = Cstr(request.form("radiobutton"))
This should solve your initial 500 error. Enclosing within Cstr() isn't actually necessary, but it's the VBScript way of converting to a string.
I don't think your radio button group will work as you have coded it. If you're trying to preserve the original submitted value you should do something like this.
<input type="radio" name="radiobutton" value="1" <% If request.form("education") = "1" Then Response.write "checked" End if %> /> Some High School <br />
<input type="radio" name="radiobutton" value="2" <% If request.form("education") = "2" Then Response.write "checked" End if %> /> Completed high School <br />
<input type="radio" name="radiobutton" value="3" <% If request.form("education") = "3" Then Response.write "checked" End if %> />Some College Education <br />
<input type="radio" name="radiobutton" value="4" <% If request.form("education") = "4" Then Response.write "checked" End if %>/> Completed a B.S Degree <br />
<input type="radio" name="radiobutton" value="5" <% If request.form("education") = "5" Then Response.write "checked" End if %>/> Completed a Master Degree <br /> <br/>
I'd suggest that having a second form on a different page isn't the best way to do form validation, better to have the form post to itself and use conditional statements to make error messages appear beside the individual form elements if nothing if they're left empty.
Finally, look at this page - it tells you how to enable useful error messages in Classic ASP.
http://www.chestysoft.com/asp-error-messages.asp

Classic ASP multiple checkbox click redirect to same page with value

I am doing some search based on check box value. If I select one checkbox I need to one value if I select second checkbox also need 2 checkbox values.
Currently I have code with radio buttons.Need to convert them to checkboxes with multiple selections. Based on request value, it will pass to a stored procedure.
<% if request("view")="Key CIA Initiative" then %>
<input type="radio" checked="checked"
onclick="javascript:document.location='Index.asp?view=Key CIA Initiative'" />
<input type="radio" onclick="javascript:document.location='Index.asp?view=High'" />
<input type="radio" onclick="javascript:document.location='Index.asp'" />
<% else %>
<% if request("view")="High" then %>
<input type="radio" onclick="javascript:document.location='Index.asp?view=Key
Initiative'" />
<input type="radio" checked="checked" onclick="javascript:document.location='Index.asp?
view=High'" />
<input type="radio" onclick="javascript:document.location='Index.asp'" />
<% else %>
<input type="radio" onclick="javascript:document.location='Index.asp?view=Key CIA
Initiative'" />
<input type="radio" onclick="javascript:document.location='Index.asp?view=High'" />
<input type="radio" onclick="javascript:document.location='Index.asp'" />
<%end if%>
<%end if%>
When the radio buttons are clicked, it redirects to same page with request value ,then I am passing to the stored procedure
If request("view")="Key CIA Initiative" Then
strSQL = "Exec sp_get_Project_list 'Key CIA Initiative' "
Else
If request("view")= "High" then
strSQL="Exec sp_get_Project_list 'High' "
Else
strSQL="Exec sp_get_Project_list "
end if
end if
You will have to do something like this:
<%
Response.write "Request(view)="& request("view") & "<br />"
'Now, if request("view") has nultiple values, How are you going to call the sp?
'pass both values to it?
If Trim(Request("view"))<>"" Then
If InStr(Request("view"),"All")<>0 Then
strSQL="Exec sp_get_Project_list"
Else
strSQL = "Exec sp_get_Project_list '"& Request("view") &"'"
End if
Response.write "strSQL ="& strSQL & "<br />"
End If
%>
<form>
<input type="checkbox" name="view" value="Key CIA Initiative" <% if InStr(request("view"),"Key CIA Initiative")>0 then %> checked="checked"<%End If%> />Key CIA Initiative <br/>
<input type="checkbox" name="view" value="High" <%if InStr(request("view"),"High")>0 then %> checked="checked"<%End If%> />High<br/>
<input type="checkbox" name="view" value="All" <%if InStr(request("view"),"All")>0 then %> checked="checked"<%End If%> />All <br/>
<input type="submit">
</form>

Why my checkBox statement doesnt works?

Why my checkBox statements doesnt works?I've used session as you seen(because my homework so dissmiss if it usefull or not):
<form id="ShoppingCart" action="Final.aspx">
<input type="checkbox" runat="server" id="CallOfDutyCheckBox" />
<%
if (CallOfDutyCheckBox.Checked)
Session["Username_CallOfDutyCheckBox_price"] = "5";
%>
<input type="submit" value="Buy It" />
</form>
<form id="Final">
<div>
<%
Response.Write(Session["Username_CallOfDutyCheckBox_price"]);
%>
</div>
</form>
Do you understand when you click the checkbox, the code at the server does not run yet? Click submit to submit the form with the value of the checkbox.

Dynamic form in classic asp

I have created a dynamic form using vbscript. It displays fine but when I click on submit button it does not post the page back... Can anyone help me? Code I have written is:
<form method="post" action="home.asp">
<%if session("id")="" then
response.write("<div id=logindiv>Login ID: <input type=text ID=loginID name=loginID /><br/><br/>Password: <input type=password ID=password name = password/><br/><br/><a href=register.asp/>Sign Up</a> <input type=submit id=loginbtn name=loginbtn value=Login /></div>")
else
response.write("already logged in")
end if%>
</form>
The resulting html is this:
<form method="post" action="home.asp">
<div id=logindiv>Login ID: <input type=text ID=loginID name=loginID /><br/><br/>Password: <input type=password ID=password name = password/><br/><br/><a href=register.asp/>Sign Up</a> <input type=submit id=loginbtn name=loginbtn value=Login /></div>
</form>
Looks like you have an extra / in your anchor tag:
<a href=register.asp/>
Maybe unrelated, but if it's closing the element, the after "Sign Up" could be screwing up the .

One submit to make a Query in HTML-ASP page and a normal submit

I want to have a Query been executed when I press the button, then follow filling other filds. Everything works fine if I only execute the Query, but I put the other steps then the Query is not executed.
I will really appreciate any kind of help
Here are the codes :
<form action="" method="POST">
<%
set conn=Server.CreateObject("ADODB.Connection")
conn.Provider="Microsoft.Jet.OLEDB.4.0"
conn.Open(Server.Mappath("/db/TextDB.mdb"))
set rs=Server.CreateObject("ADODB.recordset")
sql="SELECT Country FROM TheCountries ORDER BY Country"
rs.Open sql,conn
country=request.form("country")
%>
Select the Country <select name="country">
<% do until rs.EOF
response.write("<option")
if rs.fields("country")=country then
response.write(" selected")
end if
response.write(">")
response.write(rs.fields("Country"))
rs.MoveNext
loop
rs.Close
set rs=Nothing %>
</select>
<input type="submit" value="Show Countries">
<%
if country<>"" then
sql="SELECT Country, City, Cost FROM TheCities WHERE country='" & country & "' Order by City"
set rs=Server.CreateObject("ADODB.Recordset")
rs.Open sql,conn
city=request.form("city")
cost=request.form("cost")
%>
<br>
Select The City <select name="city">,
<% do until rs.EOF
response.write("<option")
if rs.fields("city")=city then
response.write(" selected")
end if
response.write(">")
response.write(rs.fields("City") & " " & rs.fields("Codigo"))
rs.MoveNext
loop
rs.Close
conn.Close
set rs=Nothing
set conn=Nothing%>
</select>
<% end if %>
</form>
<center>
<table border="0" cellpadding="0" cellspacing="0" width="80%"><tr><td>
<form action="_gdForm/webformmailer.asp" method="POST" target="_top" class="formmargin">
<input type="hidden" name="recipient" value="ramon_batista#hotmail.com">
<input type="hidden" name="subject" value="WebSite Contact">
<input type="hidden" name="redirect" value="/thanksespanol.htm">
<input type="hidden" name="required" value="your_name,phone,country,city">
<input type="hidden" name="sort" value="your_name,phone,country,city">
<table border="0" cellpadding="1" cellspacing="0" width="100%">
<tr><td>
Name:<br>
</td></tr><tr><td>
<input type="text" name="your_name" size="40" class="shadeform"><br>
</td></tr><tr><td>
</td></tr><tr><td>
<script language="JavaScript" type="text/javascript" src="myscrip.js"></script>
<script language="JavaScript" type="text/javascript">
</script>
#user633228: You've got two forms. The first query isn't part of the second form which is why it isn't submitting along with it. What you can perhaps do is only display the first form and then only show the second one with
If country <> "" Then
' Show other form
End If
Add another <input type="hidden" name="country" value="<%=country %>"> to the second form so country's value will be sent along.

Resources