Hi I'm new to classic asp and i just can't get my head around this simple problem. I have a form with 2 checkbox's in and this is the result i want:
If the user checks both checkbox's then insert a certain value into the database. Else insert a different value into the database. I've tried a few things but at the moment i'm trying to check if the checkbox doesn't have a value then insert but the else always fires.
By default the user has to accept the terms checkbox.
Hope this makes sense. Thanks
<FORM method="POST" action="<% =Request.ServerVariables("SCRIPT_NAME")%>" >
<p> <input type="checkbox" name="Privacy" value="1" id="Privacy" >privacy checkbox<img src="/images/qmark.png" /></p>
<p> <input onchange="this.setCustomValidity(validity.valueMissing ? 'Please indicate that you accept the Terms and Conditions' : '');" id="field_terms" type="checkbox" name="Terms" value="2" >I accept Terms and Conditions</p>
</form>
Then my asp looks like:
if Request.form("Privacy") <> "" Then
SQL = "INSERT INTO table1 (t1_accept) VALUES('N')"
cnSub.execute SQL
Else
SQL = "INSERT INTO table1 (t1_accept) VALUES('Y')"
cnSub.execute SQL
End If
Lets look at three cases:
CASE 1 You have 5 inputs of type TEXT with the same name, e.g., Studiox
The request.form(“Studiox”) will give you a string with the values of ALL 5 inputs, separated by a comma (v1, v2, v3, v4, v5).
CASE 2 You have 5 inputs of type CHECKBOX with the same name, e.g., Studiox
The request.form(“Studiox”) will also give you a string BUT ONLY with the values of CHECKED inputs, separated by a comma (e.g. v1, v3, v5).
CASE 3. You have 2 (or more) inputs of type CHECKBOX with DIFFERENT names, e.g., Studio_x and Studio_y.
The logical conclusion of CASE 1 and CASE 2 is that NOT CHECKED Checkboxes does Not send any value!
So, You can test if Studio_x is checked as follows: if request.form(“Studio_x”) <> “” then Checked.
Try this:
If Request.Form("Privacy") = "1" Then
SQL = "INSERT INTO table1 (t1_accept) VALUES('Y')"
Else
SQL = "INSERT INTO table1 (t1_accept) VALUES('N')"
End If
cnSub.execute SQL
Note this code does an explicit check if Privacy has a value of 1, if it is insert a value of Y into the table, otherwise any other value for Privacy will insert a value of N into the table.
Related
Sometimes during Dynamics NAV development, it is helpful to take a quick look at the data using SQL Server. But because any fields of type option are an enumeration, all you get in SQL Server is the numeric value. I needed a quick and dirty way to get the option text values instead.
From within NAV you can read the OPTIONSTRING property of a FieldReference. This is a comma separated string. A job can be scheduled that will loop through all of the tables (Object virtual table filtered on table) by number, find the options strings and add them to a table. Then in a query you can find the option text value for the Table, Field No, and Field Value.
RecRef.OPEN(TableNo);
FOR i := 1 TO RecRef.FIELDCOUNT DO BEGIN
FieldRef := RecRef.FIELDINDEX(i);
IF FORMAT(FieldRef.TYPE) = 'Option' THEN BEGIN
optionstring := FieldRef.OPTIONSTRING;
c := NumberofOptions(optionstring);
FOR o := 1 TO c DO BEGIN
OptionsTable.INIT;
OptionsTable."Table No" := TableNo;
OptionsTable."Field No" := FieldRef.NUMBER;
OptionsTable."Option Value" := o-1;
OptionsTable."Option Text" := SELECTSTR(o, optionstring);
OptionsTable."Field Name" := FieldRef.NAME;
IF NOT OptionsTable.INSERT THEN OptionsTable.DELETE;
END;
END;
END;
To make this a little less painful, I created a macro enabled Excel file that parses the Dynamics NAV field option string into a Sql Server T-Sql Case statement. It provides a horizontal or vertical case statement and uses the field name as the column alias in Sql Server. Enjoy...
Here is a link to the Excel file
Excel File
I often get this problem. I created a table with option values (int) and names (string). The primary key is code, value. So you can use it also to resolve magicnumbers from other systems. Then you can easy join this table:
select Type, i.[Option] [Option Name]
from Object o
join [xxx$IntegerToOption] i on i.Code = 'OBJEKT TYP' and i.Integer = o.Type
order by o.Name
Output:
Type Option Name
5 Codeunit
2 Form
1 Table
2 Form
2 Form
1 Table
2 Form
5 Codeunit
3 Report
My system require me to use VbScript
My Situation is
I have 2 table, named CoverTypes(coverID,coverName data) and InsuCover(selected CoverID and coverName data by user).
I want to display all the data in CoverTypes with checkbox (is checked) if the data is also in insuCover table, and unchecked if there is no same data
What I did so far is
My Query
coverTypes.Open "SELECT * FROM preregister.coverType", conn, 1
insuCover.Open "SELECT * FROM insuCover where insuranceReqId = '"& insFireReqID&"'",conn, 1
Code to Display
<% Do While Not coverTypes.EOF%>
<% if insuCover("coverId") = coverTypes("coverID") then%>
<label id="coverID" name="coverNm"><%=coverTypes("coverNm")%></label>
<input checked ="True" id="item_isSelected" name="item.isSelected" type="checkbox" value="<%=coverTypes("coverId")%>" /><br>
<% else %>
<label id="coverID" name="coverNm"><%=coverTypes("coverNm")%></label>
<input id="item_isSelected" name="item.isSelected" type="checkbox" value="<%=coverTypes("coverId")%>" /><br>
<% end if%>
<% coverTypes.MoveNext %>
<% Loop %>
The problem is
Currently only one checkbox is selected since I do not loop insuCover, but when I loop 2 table and compare, all the data get repeated many times. How should I display all the data in CoverTypes and make the checkbox to true if the data is also present in insuCover table?
Thank you.
I created the tables using just the two columns you provided, ignoring the insuranceReqId column.
The basic statement would link both tables using the coverID, with a LEFT join that will return all values from CoverTypes table, and return the the NULLs from the insuCover where the coverID's are not present. With a simple CASE statement we can test if the data is present in the second table and output a suitable column either as 1 (checked) or 0 (unchecked) that you can use to determine the .checked state of the checkbox on the UI.
SELECT p.coverID, p.coverName, CASE WHEN i.coverID IS NULL THEN 0 ELSE 1 END IsChecked, i.coverID, i.coverName
FROM preregister.coverType p
LEFT JOIN InsuCover i ON p.coverID = i.coverID
You can ignore the last two columns in the output as they are only there to check the results visually.
I have 3 simple parameters, all which are text, and allow for multiple values as well as blank values. There are no available values or default values, as I want the users to type the value themselves. When leaving all parameters blank, no data is shown, because there are no blank values. However, I want to show all data when there is no value entered for the parameter. How can I do this?
This is what the query looks like right now
SELECT [PROGRAMNO]
,[ACCTNO]
,[CLAIMNO]
,[TOTALCHARGES]
,[TOTALPAYMENT]
,[TYPE]
FROM DATALINE
WHERE PROGRAMNO IN (#PROGRAMNO)
AND ACCTNO IN (#ACCTNO)
AND CLAIMNO IN (#CLAIMNO)
You can add an OR to allow for the NULL (or blank) value for each condition - depending on which you have allowed in the parameter.
WHERE (PROGRAMNO IN (#PROGRAMNO) OR #PROGRAMNO is null)
AND (ACCTNO IN (#ACCTNO) OR #ACCTNO IS NULL)
AND (CLAIMNO IN (#CLAIMNO) OR #CLAIMNO IS NULL)
or if you allow blank values instead:
WHERE (PROGRAMNO IN (#PROGRAMNO) OR #PROGRAMNO = '' )
AND (ACCTNO IN (#ACCTNO) OR #ACCTNO = '' )
AND (CLAIMNO IN (#CLAIMNO) OR #CLAIMNO = '' )
Multi-value parameters do not allow blank input. So you will need to add an item to your dropdown list that represents the blank value. If you are manually specifying the available values you would simply add this to the list. The value would be blank and the label could be something like "Blank" or "N/A". If you are using a query to populate the available values you will need to UNION this blank value to the other results. Either way, you'll also need to account for this in your WHERE clause in the main dataset as Hannover Fist pointed out.
I have a multiple drop down list populated from database. How do I insert the selected records into database? I am using Classic ASP. Here is my addstudent.asp file...
<select name="myic" id="myic" multiple="multiple">
<%While (NOT listall.EOF)%>
<option value="<%=(listall.Fields.Item("ICNO").Value)%>">
<%=(listall.Fields.Item("Class").Value)%>-<%=(listall.Fields.Item("StudentName").Value)%>
</option>
<%listall.MoveNext()
Wend
If (listall.CursorType > 0) Then
listall.MoveFirst
Else
listall.Requery
End If%>
Post the form to another script (or the same page if you like) using a form with an action set to the url of the receiving script.
form method="post" action="[your script url]"
Grab the field value using:
myic = Request.Form("myic")
From memory this will be a comma separated string as its coming from a multiple select. So split the string to get all the values:
MyArray=Split(myic,",")
Then iterate through the array to store the values in the database
For i=0 To UBound(MyArray)
myVal=Trim(MyArray(i))
[send myVal to the db]
Next
Note the use of trim as the csv string can also contain spaces.
Good day. I would like to know why a Parameter Request pops up when executing a query. I have a form with 2 comboboxes where the 2nd one depends on the value in the 1st one. I do know how to do this when it involves 2 tables. I am having trouble when there is a many to many relationship.
Table 1: name - Supply_Sources, fields - Source_ID(pk), SupplySourceName
Table 2: name - Warehouse_Locations, fields - WLocation_ID(pk), Location_Name
Table 3 (junction): name - SupplySource_WarehouseLocation, fields - Supply_Source_ID(pk), Location_In_ID(pk)
On my form frmInventoryReceivedInput I have cboSupplySource and cboWLocation.
I populate cboSupplySource with
SELECT [Supply_Sources].[Source_ID], [Supply_Sources].[SupplySourceName] FROM Supply_Sources;
I am trying to get a drop down list in the cboWLocation based on the value in cboSupplySource. I am wanting to see the location names of where the supplies are placed in the warehouse.
I have a requery in cboSupplySource After Update (with cboWLocation as the control name). The SQL that I have come up with so far is:
SELECT Warehouse_Locations.Location_Name,
SupplySource_WarehouseLocation.Supply_Source_ID,
SupplySource_WarehouseLocation.Location_In_ID
FROM Warehouse_Locations RIGHT JOIN (Supply_Sources LEFT JOIN
SupplySource_WarehouseLocation ON Supply_Sources.Source_ID =
SupplySource_WarehouseLocation.Supply_Source_ID) ON
Warehouse_Locations.WLocation_ID =
SupplySource_WarehouseLocation.Location_In_ID
WHERE (((Warehouse_Locations.Location_Name)=[frmInventoryReceivedInput].[cboSupplySource]));
When it runs, on tabbing out of cboSupplySource, Enter Parameter Value dialogue box pops up, looking for frmInventoryReceivedInput.cboSupplySource input. Nothing I input brings up the correct list in cboWLocation.
Obviously, I do not have the correct select statement. Any help would be appreciated.
For cboWLocation try the recordSource query:
SELECT Warehouse_Locations.Location_Name
FROM Warehouse_Locations INNER JOIN (Supply_Sources INNER JOIN
SupplySource_WarehouseLocation ON Supply_Sources.Source_ID =
SupplySource_WarehouseLocation.Supply_Source_ID) ON
Warehouse_Locations.WLocation_ID =
SupplySource_WarehouseLocation.Location_In_ID
WHERE ((Supply_Sources.SupplySourceName)=([Forms]![frmInventoryReceivedInput].[cboSupplySource]))
Be aware, that the combobox columns have to be set to columncount 1 in this case with appropriate column width, because you said you only want to see the location names. Further, you should be sure that cboWLocation is not bound to a Control Source, to not overwrite anything.
You can apply it in VBA at the cboWLocation Enter Event.
In the following code example, the combobox cboWLocation is only updated, if there is a value in combobox cboSupplySource.
Private Sub cboWLocation_Enter()
If not (isNull(Me!cboSupplySource) Or Me!cboSupplySource.ListIndex = -1) then
Me.cboWLocation.RowSource = strSQL 'Put here the previous mentioned SQLString
End if
End Sub
HINT: It would be better for performance, when you change the bound column in cboSupplySource to the PK SourceID instead of the name. (With two columns in combobox cboSupplySource) Then use this PK to compare in your WHERE statement instead of the name. this is what keys in tables are for.
Edit: In the WHERE statement, maybe you have to put the namecomparison between ' ' because it is a string