writing output to a dropdown list - asp-classic

<%
dim req_id
req_id=Request.Form("Req_id")
Set conn=server.CreateObject("adodb.connection")
conn.Open session("Psrconnect")
Set rs=CreateObject("Adodb.Recordset")
rs.Open "select * from releases where project like '%"&req_id&"%'", conn
%>
<SELECT style="LEFT: 454px; WIDTH: 500px; TOP: 413px" name="txtrelease1" id="txtrelease1">
<%
if rs.EOF=true then
%>
<OPTION value="NO Request to Edit">No Request to Edit</OPTION>
<% else
do while rs.EOF<>true
p=InStrRev(rs.Fields(0),"\")
q=Len(rs.Fields(0))
r=(Right(rs.Fields(0),(q-p))) %>
<OPTION value=<%=rs.Fields(0)%>> r </OPTION>
<%
rs.movenext
loop
end if
%>
</SELECT>
i want to right the value of r in the dropdown list. i dont know the syntax. as of now the drop down list shows "r" , not the value inside it. how to do it?

This should do it:
do while not rs.EOF
p=InStrRev(rs.Fields(0),"\")
q=Len(rs.Fields(0))
r=(Right(rs.Fields(0),(q-p)))
%>
<option value="<%=rs.Fields(0)%>"><% =r %></option>
<%
rs.moveNext
loop

Related

Classic ASP dropdown menus, hold values

i'm working on something. So, i go to my Database and I want to ask what type of machine they want (base on the existings at the DB)
Then, i will check the model, depending on the type.
Last, The number of palets
exampe:
machine 1 has model 2, 3 and 4
machine 2 has model 1, 2 and 3
machine 1, model 2 has 13 palets, machine 2 model 2 has 15 palets
my code:
main.asp
<!DOCTYPE html>
<html>
<head>
<link href="mystyle.css" rel="stylesheet" type="text/css"/>
<script src="javascript/jquery-1.11.3.min.js"></script>
</head>
<body>
<!--Inicialization, ...-->
<%
dim model, typee, palete
typee=""
model=""
palete=""
dim perguntas(20)
Set conn = Server.CreateObject("ADODB.Connection")
Set conn2 = Server.CreateObject("ADODB.Connection")
conn_string = "Provider=sqloledb;Server=INF0148\SQLEXPRESS;Database=#####;Uid=####;Pwd=###########"
conn.commandTimeout = 60
conn.Open conn_string
Set rs = Server.CreateObject("ADODB.Recordset")
Set rs2 = Server.CreateObject("ADODB.Recordset")
function options(value, data, select_id)
Response.Write ("<option value=""" & value & """")
if request.form(select_id) = value then
Response.Write ("selected")
end if
Response.Write(">" & data & "</option>")
end function
%>
<div id="main">
<!--choose type of machine-->
<form method="post">
<select name="maq" id="maq" onchange="this.form.submit()">
<option value="">Type of Machine:</option>
<%
conn.close
conn.Open conn_string
rs.Open "SELECT DISTINCT Type FROM models", conn
do until rs.EOF
for each x in rs.Fields
options x.value, x.value, "maq"
next
rs.MoveNext
loop
%>
</select>
</form>
<%typee=Request.Form("maq")%>
<!--Choose model-->
<form method="form">
<select name="model" id="model" onchange="this.form.submit()">
<option value="">Model:</option>
<%
conn.close
conn.Open conn_string
rs.Open "SELECT DISTINCT Model FROM models WHERE Type='"&typee&"'", conn
do until rs.EOF
for each x in rs.Fields
options x.value, x.value, "model"
next
rs.MoveNext
loop
model=Request.Form("model")
%>
</select>
</form>
<!--Number of Palets-->
<form method="post">
<%
conn.close
conn.Open conn_string
rs.Open "SELECT N_Palets FROM Models WHERE Type='"&typee&"' AND Model='"&model&"'", conn
dim temp
temp=0
do until rs.EOF
for each x in rs.Fields
if not IsNull(x.value) then
if temp=0 then
response.write("<select name=palets id=palets onchange=""this.form.submit()"";>")
response.write("<option value="">Number of Palets:</option>")
temp=1
end if
options x.value, x.value, "palets"
end if
next
rs.MoveNext
loop
paletes=Request.Form("palets")
%>
</form>
</div>
</body>
</html>
so, when i choose the type... it's ok, the page displays the right models... when i choose the model, page reload and i loose everything.
Can you help me?
Submitting a form only submits the fields that are on that form, not any of the other fields on other forms. That's why submitting one of your child forms loses everything. To fix it, add hidden fields with the necessary parent data.
<!--Choose model-->
<form method="post">
<input type="hidden" name="maq" value="<%=Request.Form("maq")%>">
<select name="model" id="model" onchange="this.form.submit()">
[...]
</select>
</form>
For the palets form, add both the machine & model as hidden fields.

save the checked items in checkbox to session

Need help. I want to save the items that are check in my checkbox to a Session.
What I'm doing is get the value of the items that are checked and store it in an array. Then I will assign that value as Session Name and assign a value of 1 to the session.
This is the code that I'm using but it only gets the first item that is checked.
dim checkboxList
checkboxList = request.Form("schedule")
checkboxList = split(checkboxList, ",")
for each i in checkboxList
Session(i) = 1
next
for example If I check A and B on my Checkbox I should get
Session("A")=1 and Session("B")=1
but the only thing i'm getting is Session("A")=1
I tried checking if I'm getting the right item on the my Array by Using this code and the data is correct.
dim checkboxList
checkboxList = request.Form("schedule")
checkboxList = split(checkboxList, ",")
for each i in checkboxList
response.write(i)
next
Here is my Html Code.
<form class="well" method="post" action="applicationSave.asp">
<div class="controls">
<input type="checkbox" id="onShifts" name="schedule" value="onShifts" <% if Session("onShifts") = 1 then response.Write("checked") end if %> /> On Shifts?<br>
<input type="checkbox" id="nightShifts" name="schedule" value="nightShifts" <% if Session("nightShifts") = 1 then response.Write("checked") end if %> /> Night Shifts?<br>
<input type="checkbox" id="partTime" name="schedule" value="partTime" <% if Session("partTime") = 1 then response.Write("checked") end if %> /> Part Time?<br>
<input type="checkbox" id="fullTime" name="schedule" value="fullTime" <% if Session("fullTime") = 1 then response.Write("checked") end if %> /> Full Time<br>
<input type="checkbox" id="holidays" name="schedule" value="holidays" <% if Session("holidays") = 1 then response.Write("checked") end if %> /> Holidays/Sundays?<br>
<input type="checkbox" id="projectBasis" name="schedule" value="projectBasis" <% if Session("projectBasis") = 1 then response.Write("checked") end if %> /> Project Basis
</div>
</form>
This is because values delimited with ", " (comma-space), instead "," only.
So, before working with array make "trimming" items:
Dim i
For i = 0 To UBound(checkboxList)
checkboxList(i) = Trim(checlboxList(i))
Next
Another way - write Session(Trim(i)) = 1 in for statement.
BTW: Commonly, your code is unsafe. E.g, you have some session bool variable Session("IsAuthorized"). Visitor can send request to your .asp file with value schedule=IsAuthorized...

End of statement expected bind dropdown

I have a combobox with a condition. I would like to bind with the condition, but when I run it, I get the error End of statement expected.
However, when I comment out these line it work perfect.
<li>
<select name="account_type">
<option value="I" <% If Request.Form("account_type") = "I" Then Response.Write("SELECTED") End If %> ">Individual</option>
<option value="C" <% If Request.Form("account_type") = "C" Then Response.Write("SELECTED") End IF %>>Corporate</option>
</select>
</li>
What I am doing wrong with this?
I am using VB.Net Inline coding.
'End If' is only used for multi-line If blocks. If the action is on the same line as the condition then you don't use 'End If'. Also, you ought to count your double quotes because they don;t seem to match.

Creating article pagination

Hi I'm using silverstripe 2.4.7 and I'm having difficulty getting the pagination to work. I've created a function in my page.php to get the latest articles like so
function AllNewsPosts($num=1) {
$news = DataObject::get_one("NewsHolder");
return ($news) ? DataObject::get("NewsEntry", "ParentID > 0", "Date DESC", "", $num) : false;
}
Then when i put this function into the control and pagination tags one article shows up however the links to the concurrent articles do not work - essentially the pagination is not working and I'm not sure how to fix it
<% if AllNewsPosts %>
<% control AllNewsPosts %>
<div class="event">
<h2>$MenuTitle |<span class="date"> $Date.Time $Date.Long</span></h2>
<p>$Content.FirstParagraph</p>
See more about this event
</div>
<% end_control %>
<% else %>
<div class="no-entry">'There are no entries'</div>
<% end_if %>
<% if AllNewsPosts.MoreThanOnePage %>
<div id="PageNumbers">
<p>
<% if AllNewsPosts.NotFirstPage %>
<a class="prev" href="$AllNewsPosts.PrevLink" title="View the previous page"><span class="yellow-background">Prev</span></a>
<% end_if %>
<span>
<% control AllNewsPosts.PaginationSummary(0) %>
<% if CurrentBool %>
<span class="current">$PageNum</span>
<% else %>
<% if Link %>
$PageNum
<% else %>
…
<% end_if %>
<% end_if %>
<% end_control %>
</span>
<% if AllNewsPosts.NotLastPage %>
<a class="next" href="$AllNewsPosts.NextLink" title="View the next page"><span class="yellow-background">Next</span></a>
<% end_if %>
</p>
</div>
<% end_if %>
Any help is much appreciated
Note: The following answer is for Silverstripe 2.4. This should not be used for Silverstripe 3.0+ sites. From 3.0 and onwards the PaginatedList object makes pagination much easier.
You are not setting a limit on how many entries to retrieve in your query, or where to start from.
The following tutorial explains how to apply pagination to a set of data objects exactly as you are trying to do:
http://www.ssbits.com/tutorials/2010/paginating-a-filtered-dataobjectset/
Here is an attempt at altering your function to include limit and start as needed for pagination:
PHP
function AllNewsPosts() {
if(!isset($_GET['start']) || !is_numeric($_GET['start']) || (int)$_GET['start'] < 1)
{
$_GET['start'] = 0;
}
$SQL_start = (int)$_GET['start'];
$newsEntries = DataObject::get('NewsEntry', '', 'Date DESC');
$doSet = new DataObjectSet();
foreach ($newsEntries as $newsEntry) {
if ($newsEntry->canView()) {
$doSet->push($newsEntry);
}
}
$doSet->setPageLimits($SQL_start, 10, $doSet->Count());
return $doSet;
}
Note the above will display 10 items per page. You can change this to however you need per page.

HTML 'id' attribute for items in dropdown made from html helper

Can we set an id attribute as I would for something like a table column via:
for an html dropdown list element that is created with a helper such as:
<% for (int i = 0; i < Model.Trx.TransactionHolidayCityCollection.Count; i++)
{%>
<%= i > 0 ? "," : "" %>
<%= DropDownData.HolidayDays().ToList().Find(item => item.Value == Model.Trx.TransactionHolidayCityCollection[i].HolidayCityID.Value.ToString()).Text %>
<%} %>
You don't need a helper, necessarily:
<select id="holidayCities" name="holidayCities">
<% foreach (HolidayCity city in Model.Trx.TransactionHolidayCityCollection) { %>
<option
value="<%=city.HolidayCityID.Value %>"
id="holidayCity_<%=city.HolidayCityID.Value %>"
><%=city.Name %></option>
<% } %>
</select>
If you wanted to use the HtmlHelper you can write:
<%=Html.DropDownList("holidayCities", Model.HolidayCitiesSelectList) %>
Model.HolidayCitiesSelectList should be of type IEnumerable<SelectListItem>
This type of customization isn't avaiable for the built in helpers so you might end up creating your own Html.DropDownList helper method.
http://msdn.microsoft.com/en-us/library/system.web.mvc.selectlistitem(v=vs.98).aspx

Resources