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.
Related
Here is the .aspx file
<form id="form1" runat="server">
<input type="text" id="StringValue" runat="server"/>
<datalist id="dataList" runat="server"></datalist>
<% CreateContent(_sql)%>
</form>
And here is the .vb file (CreateContent)
Protected Sub CreateContent(ByVal sql As String)
Dim optList As New List(Of String)
optList = GetData(sql)
Dim table As New DataTable()
table.Columns.Add(New DataColumn("DataOptions"))
For Each opt In optList
table.Rows.Add(opt)
Next
For Each row In table.Rows
dataList.InnerHtml = dataList.InnerHtml & vbCrLf & String.Format("<option value='{0}'>", row(0))
Next
MsgBox(dataList.InnerHtml)
End Sub
When I tested the page, the MsgBox could actually show all the <option> elements. However, these contents can only exist in server side. <datalist> is always empty in page source. Anyone can explain what prevent the content being passed to the page and how to solve it?
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...
I'm having a problem here. I've created a page for adding records into a database, it's working fine however the asp script is running every time the page loads, inputting a blank record to the database each time the page is loaded, this is very annoying as it messes with other scripts I have. I feel I am being very stupid but all I need is for the script to run only once the submit button has been clicked, how do I get it to do this?
<!DOCTYPE html>
<html>
<title>
Teacher Registration
</title>
<body>
<h1>
Teacher registration
</h1>
<form name="teacherReg" action="Registration.asp" method="POST">
First name:<input type="text" name="firstname"><br>
Last name:<input type="text" name="lastname"><br>
Password :<input type="password" name="password">
<input type="submit" value="submit">
</form>
<%
set conn=Server.CreateObject("ADODB.Connection")
conn.Open ="Driver={SQL Server}; Server=QuizDynamics.db.11989315.hostedresource.com; Database=QuizDynamics; Uid=QuizDynamics; Pwd=Compostheap12!;"
set rs=Server.CreateObject("ADODB.recordset")
rs.Open "Select * from teachers", conn
sql="INSERT INTO teachers (firstname, password, lastname)"
sql=sql & " VALUES "
sql=sql & "('" & Request.Form("firstname") & "',"
sql=sql & "'" & Request.Form("password") & "',"
sql=sql & "'" & Request.Form("lastname") & "')"
on error resume next
conn.Execute sql,recaffected
if err<>0 then
Response.Write("No update permissions!")
else
Response.Write("<h3>" & recaffected & " record added</h3>")
end if
conn.close
%>
</body>
</html>
Give your submit input a name attribute - eg submitbutton - then do something like
if request.form("submitbutton") <> "" then
'put your insert code here
End if
So i'm using ADO to add data into a sql database, here's my raw code:
<!DOCTYPE html>
<html>
<body>
<h1>
Teacher registration
</h1>
<form name="teacherReg" action="http://hr-computing/public/AlexS/Tests/login.asp" method="POST">
First name:<input type="text" name="firstname"><br>
Last name:<input type="text" name"lastname">
<input type="submit" value="submit">
</form>
<%
set conn=Server.CreateObject("ADODB.Connection")
conn.Open ={ private }
set rs=Server.CreateObject("ADODB.recordset")
rs.Open "Select * from teachers", conn
sql="INSERT INTO teachers (firstname, lastname)"
sql=sql & " VALUES "
sql=sql & "('" & Request.Form("firstname") & "',"
sql=sql & "'" & Request.Form("lastname") & "')"
on error resume next
conn.Execute sql,recaffected
if err<>0 then
Response.Write("No update permissions!")
else
Response.Write("<h3>" & recaffected & " record added</h3>")
end if
conn.close
%>
</body>
</html>
It's working but only adding the value of firstname into the table, not lastname aswell, I can't see where i'm going wrong, any help guys?
Change <input type="text" name"lastname">
to
<input type="text" name="lastname">
You are missing an equals sign.
<%
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