I asked a few month back how to hide a few drop down option on a Classic ASP page which were being pulled from a database so that users could not select those options. But now on one of the remaining options there appear 3 radio box options. I have to remove one of those options. The option which I need to remove is called value="_BML7(B)" according to Chrome.
The last time I inserted the following code into the following code into the include.asp file which worked great but that was to hide drop down options. This I need to hide one radio button option from the current drop down options.
Sub buildDropDownList(strCurrentSelection, objListData, strCodeName, strDescriptionName, blnIncludeOther)
If Not objListData.BOF Then
objListData.MoveFirst
End If
Dim currentCodeValue
While Not objListData.EOF
currentCodeValue = objListData(strCodeName)
If (UCase(currentCodeValue)<>"_04GIDBM") And _
(UCase(currentCodeValue)<>"_05GIDFM") And _
(UCase(currentCodeValue)<>"_03MIS(Q") And _
(UCase(currentCodeValue)<>"_06GIDMS") And _
(UCase(currentCodeValue)<>"_08EXHRM") And _
(UCase(currentCodeValue)<>"_10EXMKT") And _
(UCase(currentCodeValue)<>"_12EXTTH") And _
(UCase(currentCodeValue)<>"_15AFT") And _
(UCase(currentCodeValue)<>"_16HSC") And _
(UCase(currentCodeValue)<>"_18LTD") And _
(UCase(currentCodeValue)<>"_19EBM") And _
(UCase(currentCodeValue)<>"_17EXHSC") Then
Response.Write "<option value='" & currentCodeValue & "' "
If StrComp(strCurrentSelection, currentCodeValue, 1) = 0 then
Response.Write "selected"
End If
Response.Write ">" & objListData(strDescriptionName) & "</option>" & VbCrLf
End If
I could really use the help on this and thank everyone in advance for their help! I not very good with Classic ASP but I'm trying.
Here is the code that I inserted last time on the include.asp file.
<p align="center">
<%
do until rsProgramLevel.EOF
Response.Write "<input type=""radio"" name=""programcode"" onclick=""onProgramCode()"" "
Response.Write "value=""" & rsProgramLevel("ProgramCode") & """ "
if rsProgramLevel("ProgramCode") = strProgramCode then
Response.Write "checked"
end if
Response.Write ">"
Response.Write " "
Response.Write rsProgramLevel("LevelDescription") & " (£" & FormatNumber(rsProgramLevel("ChargeValue"), 2) & ") "
Response.Write " "
rsProgramLevel.MoveNext
loop
%>
</p>
You could compile the list into a string, like so...
Const ignoreCodes = " _04GIDBM _05GIDFM _03MIS(Q _06GIDMS _08EXHRM _10EXMKT _12EXTTH _15AFT _16HSC _18LTD _19EBM _17EXHSC "
Add it to the very top of your file (after any Option Explicit commands). If you have new codes to add to it simply ensure that there's a space either side of it.
Then just test against it...
If Instr(ignoreCodes, UCase(currentCodeValue)) = 0 Then
Response.Write("<option value='" & currentCodeValue & "' ")
If StrComp(strCurrentSelection, " " & currentCodeValue & " ", 1) = 0 then
Response.Write " selected "
End If
Response.Write(">" & objListData(strDescriptionName) & "</option>")
End If
If you think about this further, then simply include the list in a redundant codes table in a database.
To make this simple, just wrap the code sending the HTML with a basic If..Then statement:
Dim currentCode
do until rsProgramLevel.EOF
currentCode = rsProgramLevel("ProgramCode")
If UCase(currentCode)<>"_BML7(B)" Then
Response.Write "<input type=""radio"" name=""programcode"" onclick=""onProgramCode()"" "
Response.Write "value=""" & currentCode & """ "
if rsProgramLevel("ProgramCode") = strProgramCode then
Response.Write "checked"
end if
Response.Write ">"
Response.Write " "
Response.Write rsProgramLevel("LevelDescription") & " (£" & FormatNumber(rsProgramLevel("ChargeValue"), 2) & ") "
Response.Write " "
End If
rsProgramLevel.MoveNext
loop
Related
A friend of mine asked me a favor, help him to install CK Editor into SnitzForum (yeah old I know). Since I am not into asp lang. I have a problem since after putting into the head the CDN code I have to put below the tag this code:
<script> CKEDITOR.replace( 'editor1' ); </script>
So this is the part where the textarea is into the file post.asp:
<%
end if
end if
Response.Write " </font></td>" & vbNewLine & _
" </tr>" & vbNewLine & _
" </table>" & vbNewLine & _
" </font></td>" & vbNewLine & _
" <td bgColor=""" & strPopUpTableColor & """><textarea cols=""" & intCols & """ name=""editor1"" rows=""" & intRows & """ wrap=""VIRTUAL"" onselect=""storeCaret(this);"" onclick=""storeCaret(this);"" onkeyup=""storeCaret(this);"" onchange=""storeCaret(this);"">" & Trim(CleanCode(TxtMsg)) & "</textarea><br /></td>" & vbNewLine & _
" </tr>" & vbNewLine
end if
select case strRqMethod
case "Reply", "ReplyQuote", "TopicQuote"
Response.Write " <script language=""JavaScript"" type=""text/javascript"">document.PostTopic.Message.focus();</script>" & vbNewLine
end select
How can I add that script? Thanks :)
Edited Code:
<!--#INCLUDE FILE="inc_smilies.asp" -->
<%
end if
end if
Response.Write " </font></td>" & vbNewLine & _
" </tr>" & vbNewLine & _
" </table>" & vbNewLine & _
" </font></td>" & vbNewLine & _
" <td bgColor=""" & strPopUpTableColor & """><textarea cols=""" & intCols & """ name=""Message"" rows=""" & intRows & """ wrap=""VIRTUAL"" onselect=""storeCaret(this);"" onclick=""storeCaret(this);"" onkeyup=""storeCaret(this);"" onchange=""storeCaret(this);"">" & Trim(CleanCode(TxtMsg)) & "</textarea><br /></td>" & vbNewLine & _
" </tr>" & vbNewLine
%>
<script>
tinymce.init({
selector: 'textarea',
toolbar_mode: 'floating',
});
</script>
<%
end if
select case strRqMethod
case "Reply", "ReplyQuote", "TopicQuote"
Response.Write " <script language=""JavaScript"" type=""text/javascript"">document.PostTopic.Message.focus();</script>" & vbNewLine
end select
Ok, so an working example with a text box could (would) be this:
<script src="https://cdn.ckeditor.com/4.16.2/standard/ckeditor.js"></script>
<div style="width:50%">
<asp:TextBox ID="TextBox1" runat="server" Height="304px" Width="617px"
TextMode="MultiLine"
ClientIDMode="Static"
></asp:TextBox>
</div>
<script>
CKEDITOR.replace('TextBox1');
</script>
And we now get this:
So, as noted, it probably better to hide/show the one div above, then trying to inject the above markup into the page. And the REASON why is that then in code behind, you want to be able to get the textbox by using
TextBox1.text
So, by placing a plane jane text box (TextBox1) on the form, then code behind can use that text box. If you inject the markup, then code behind will have a much more difficult time using that markup and using TextBox1.Text to get the results of the markup in that text box.
So I don't see the need to use "code" to inject the above. As I noted, perhaps you need to hide/show this?
Then add a "ID" to the div like this:
<div id="mycooleditor" runat="server" style="width:35%;display:none">
<asp:TextBox ID="TextBox1" runat="server" Height="304px" Width="617px"
TextMode="MultiLine"
ClientIDMode="Static"
></asp:TextBox>
</div>
Now, in code behind, to display the editor, we can go:
mycooleditor.Style.Add("display", "normal")
So, unless you make a REALLY good case as to why we using code to inject the html into the web page as opposed just dropping in the markup as per above without any code (and saving world poverty's at the same time), then I see no reason to spend the time + effort writing code that does the same thing?
You can write code to inject, but I see no reason why when you can just drop in the markup anyway???
Overworked. Put the tinymce files in their own folder (titled "tinyMCE") below the forum root. In the file "inc_header.asp", look for this code (appx lines 240-242):
'## START - REMOVAL, MODIFICATION OR CIRCUMVENTING THIS CODE WILL VIOLATE THE SNITZ FORUMS 2000 LICENSE AGREEMENT
Response.Write "<meta name=""copyright"" content=""This Forum code is Copyright (C) 2000-09 Michael Anderson, Pierre Gorissen, Huw Reddick and Richard Kinser, Non-Forum Related code is Copyright (C) " & strCopyright & """>" & vbNewline
'## END - REMOVAL, MODIFICATION OR CIRCUMVENTING THIS CODE WILL VIOLATE THE SNITZ FORUMS 2000 LICENSE AGREEMENT
Below that bit, insert this:
If strScriptName = "post.asp" Then
Response.Write " <script src=""./tinyMCE/tinymce.js""></script>" & vbNewLine & _
" <script language=""Javascript"">tinymce.init ({" & vbNewLine & _
" selector:'textarea'," & vbNewLine & _
" theme:'modern'," & vbNewLine & _
" browser_spellcheck:'true'," & vbNewLine & _
" plugins:['advlist anchor autolink charmap code contextmenu directionality emoticons fullscreen hr insertdatetime image link lists media nonbreaking paste print preview pagebreak save searchreplace table template textcolor visualblocks visualchars wordcount']," & vbNewLine & _
" content_css:'css/combined-min.css'," & vbNewLine & _
" toolbar:'undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image | preview media fullpage | forecolor backcolor emoticons'," & vbNewLine & _
" });</script>" & vbNewLine
End If
That will take over all instances of the text area in "post.asp". If you want to use it throughout the forum for text areas, remove the If/End If lines.
See slimmed down code. I'm essentially creating a list of items (printers) along with a dynamically created unique radio button ID, and then I'd like to be able reference said Radio ID in order to toggle the Checked between True/False in Sub SetDefaultPrinter. Why? Because using Add Devices / Search is too hard for some of our users, hence, a cute little GUI. Why dynamic? Because I have multiple separate networks and I'd prefer the script to adjust itself as needed.
<html>
<head>
<title>My HTML application</title>
<HTA:APPLICATION
APPLICATIONNAME="My HTML application"
ID="MyHTMLapplication"
VERSION="1.0"/>
</head>
<script language="VBScript">
Public jj, strPrinters, strModels, strLocations
Sub Window_OnLoad
strPrinters = Array("Printer1", "Printer2")
strModels = Array("HP Color LaserJet 4525", "HP Color LaserJet 4525")
strLocations = Array("Room 1", "Room 2")
jj = UBound(strPrinters)
Call OnClickGo()
End Sub
Sub OnClickGo()
DataArea1.InnerHTML = ""
For i = 0 To jj
DataArea1.InnerHTML = DataArea1.InnerHTML & "<BR><font style=color:green;font-weight=bold;>" &_
"<input type=""" & "radio""" & " name=""" &_
strPrinters(i) & "Radio""" & " id=""" & "Radio" & i & """" &_
" title=""" & "Clicking here will set " & strPrinters(i) & " as default printer.""" &_
" onclick=""" & "SetDefaultPrinter(" & i & ")""" & " onmouseover=""" & "Pointer""" &_
" onmouseout=""" & "DefaultCursor""" & "></input>" &_
"<span id=""" & strPrinters(i) & "Span""" &_
" title=""" & "Click here delete printer mapping for " & strPrinters(i) & """" &_
" onmouseover=""" & "Pointer""" & " onmouseout=""" & "DefaultCursor""" &_
" onclick=""" & "OnClickDelete(" & i & ")""" &_
">" & strPrinters(i) & ", " & strModels(i) & ", Location: " & strLocations(i) & "</span></font>"
Next
End Sub
'========================================
'= Set Default Printer ==================
'========================================
Sub SetDefaultPrinter(ii)
DataArea2.InnerHTML = strPrinters(ii) & " would have been set as default if this was fully functional."
'
' Radio0 and Radio1 are dynamically created IDs, *really* want to somehow
' dynamically reference the dynamically created IDs.
' i.e. something like
' If ii <> 0 Then (Radio & ii).checked = False
'
If ii <> 0 Then Radio0.checked = False
If ii <> 1 Then Radio1.checked = False
End Sub
'========================================
'= Delete Printer Mapping ===============
'========================================
Sub OnClickDelete(ii)
DataArea2.InnerHTML = strPrinters(ii) & " would have been deleted if this was fully functional."
'Set wshnetwork = CreateObject("WScript.Network")
'wshnetwork.RemovePrinterConnection "\\SERVER\" & strPrinters(PrinterToDelete)
End Sub
'========================================
'= MOUSE Pointers =======================
'========================================
Sub Pointer
document.body.style.cursor = "hand"
End Sub
Sub DefaultCursor
document.body.style.cursor = "default"
End Sub
</script>
<body bgcolor="white">
<span id="DataArea1"></span>
<BR><BR><BR>
<span id="DataArea2"></span>
</body>
</html>
user2345916, I have modified your code where the variables pass like you wanted. I left your comments intact, so you can pick up where you left off. Hope this helps!
Basically, the answer to your problem lies within the button's "ID", "VALUE" and "ONCLICK" values.
The ONCLICK='SetDefaultPrinter(" & i & ")' will pass the looped number to the SubRoutine.
The SetDefaultPrinter(Radioii) sets a variable from the "ONCLICK" field of the button that sends you to that SubRoutine (In this case, it's a 0 or 1).
The "FileName = document.getElementById("Radio" & Radioii).value" gets the "VALUE" field of the button that matches the "ID" field that is set between the "()", which in your case is also the variable that was pulled from the ONCLICK.
From here, you can use (FileName) variable to do whatever you want (Match IF/THEN, etc)
<script language=vbscript>
Sub Window_OnLoad
window.resizeTo 500,300
strPrinters = Array("Printer 1", "Printer 2")
strModels = Array("HP Color LaserJet 4525", "HP Color LaserJet 4525")
strLocations = Array("Room 1", "Room 2")
jj = UBound(strPrinters)
For i = 0 To jj
strHTML1 = "<span id='Delete" & i & "' value='" & strPrinters(i) & "'title='Click here delete printer mapping for " & strPrinters(i) & "' onmouseover='Pointer' onmouseout='DefaultCursor' onclick='OnClickDelete(" & i & ")'> " & strPrinters(i) & " - " & strModels(i) & ", Location: " & strLocations(i) & "</span>"
strHTML2 = strHTML2 & "<input type='radio' name='radio' value='" & strPrinters(i) & "' id='Radio" & i & "' title='Clicking here will set " & strPrinters(i) & " as default printer.' onclick='SetDefaultPrinter(" & i & ")' onmouseover='Pointer' onmouseout='DefaultCursor'>" &_
"" & strHTML1 & "</input><br>"
DataArea1.InnerHTML = strHTML2
Next
End Sub
'========================================
'= Set Default Printer ==================
'========================================
Sub SetDefaultPrinter(Radioii)
FileName = document.getElementById("Radio" & Radioii).value
DataArea3.InnerHTML = Filename & " would have been set as default if this was fully functional."
'
' Radio0 and Radio1 are dynamically created IDs, *really* want to somehow
' dynamically reference the dynamically created IDs.
' i.e. something like
' If ii <> 0 Then (Radio & ii).checked = False
'
If Radioii = 0 Then Radio0 = False
If Radioii = 1 Then Radio1 = False
End Sub
'========================================
'= Delete Printer Mapping ===============
'========================================
Sub OnClickDelete(Deleteii)
RemoveName = document.getElementById("Delete" & Deleteii).value
DataArea3.InnerHTML = RemoveName & " would have been deleted if this was fully functional."
'Set wshnetwork = CreateObject("WScript.Network")
'wshnetwork.RemovePrinterConnection "\\SERVER\" & strPrinters(PrinterToDelete)
End Sub
'========================================
'= MOUSE Pointers =======================
'========================================
Sub Pointer
document.body.style.cursor = "hand"
End Sub
Sub DefaultCursor
document.body.style.cursor = "default"
End Sub
</script>
Using the script below, I am able to list users in an OU as expected however the output lists everything including users that are missing data in the custom ipphone field. I need help to modify the code to NOT list a user with a missing extension number in the ipphone field. "This indicates a user has left the company and should not show up on the phone list"
<%# Language=VBScript %>
<% response.Buffer = True %>
<html><head>
<title></title>
</head>
<body>
<h1>Directory</h1>
<%
' Define the AD OU that contains our users
usersOU = "LDAP://OU=IT,OU=Hollister,OU=Houston,OU=NFSmith,DC=nfsmith,DC=info"
' Make AD connection and run query
Set objCon = Server.CreateObject("ADODB.Connection")
objCon.provider ="ADsDSOObject"
objCon.Properties("User ID") = "domain\user"
objCon.Properties("Password") = "password"
objCon.Properties("Encrypt Password") = TRUE
objCon.open "Active Directory Provider"
Set objCom = CreateObject("ADODB.Command")
Set objCom.ActiveConnection = objCon
objCom.CommandText ="select givenName,sn,telephonenumber,ipphone FROM '"+ usersOU +"' where ipphone='*' ORDER by givenName"
Set objRS = objCom.Execute
' Loop over returned recordset and output HTML
Response.Write "<table>" + vbCrLf
Do While Not objRS.EOF Or objRS.BOF
Response.Write " <tr>"
Response.Write "<td>" + objRS("givenName") + "</td>"
Response.Write "<td>" + objRS("sn") + "</td>"
Response.Write "<td>" + objRS("telephonenumber") + "</td>"
Response.Write "<td>" + objRS("IPphone") + "</td>"
Response.Write "</tr>" + vbCrLf
objRS.MoveNext
Response.Flush
Loop
Response.Write "</table>"
' Clean up
objRS.Close
objCon.Close
Set objRS = Nothing
Set objCon = Nothing
Set objCom = Nothing
%>
</body>
</html>
Check if the value is Null before writing the output:
Do Until objRS.EOF
If Not IsNull(objRS("ipPhone")) Then
Response.Write " <tr><td>" + objRS("givenName")
Response.Write "</td><td>" + objRS("sn")
Response.Write "</td><td>" + objRS("telephoneNumber")
Response.Write "</td><td>" + objRS("ipPhone")
Response.Write "</td></tr>" & vbCrLf
Response.Flush
End If
objRS.MoveNext
Loop
If you don't want the NULL records at all, why don't you tell your SQL query to exclude them?
So where you have
objCom.CommandText ="select givenName,sn,telephonenumber,ipphone FROM '"+ _
usersOU +"' where ipphone='*' ORDER by givenName"
add a condition:
objCom.CommandText = "SELECT givenName, sn, telephonenumber, ipphone FROM '" & _
usersOU & "' WHERE ipphone = '*' AND ipphone IS NOT NULL ORDER BY givenName"
(I'm not sure what the purpose of ipphone = '*' is, but I don't work with Active Directory much.)
The other approach, i.e. testing for IsNull(objRS("ipPhone")) in your code, is useful if you want to do something else if the field is null — maybe add an "inactive" class, that sort of thing.
I have the following code, which used to work perfectly, But now for somes reason, doesn't.
The XML I am reading is located at: https://forex.boi.org.il/currency.xml
The following code should parse the XMl and then save the USD/ILS exchange rate. As I say, it doesnt anymore, and I cant figure out whats wrong.
forexURL = "https://forex.boi.org.il/currency.xml"
getUSDRate = 0
MyRate = 0
Set xmlObj = Server.CreateObject("MSXML2.FreeThreadedDOMDocument")
xmlObj.async = False
xmlObj.setProperty "ServerHTTPRequest", True
xmlObj.Load(forexURL)
Set xmlList = xmlObj.getElementsByTagName("CURRENCY")
Set xmlObj = Nothing
x = 1
For Each xmlItem In xmlList
response.write "<p>" & xmlItem.childNodes(0).text
response.write "<p>" & xmlItem.childNodes(1).text
response.write "<p>" & xmlItem.childNodes(2).text
response.write "<p>" & xmlItem.childNodes(3).text
response.write "<p>" & xmlItem.childNodes(4).text
response.write "<p>" & xmlItem.childNodes(5).text
response.write "<p>___________________<br />" & x & "</p>"
if xmlItem.childNodes(2).text = "USD" then
MyRate = xmlItem.childNodes(4).text
exit for
end if
x = x +1
Next
Set xmlList = Nothing
I suspect (wild guess ahead) changes to the way SSL is handled on the server side as the cause of your trouble. Maybe they disabled older, more insecure ciphers in response to recent SSL bugs.
Like #John notes - when you change from MSXML2.FreeThreadedDOMDocument (which loads version MSXML2 version 3) to explicitly load the more modern version 6 (MSXML2.FreeThreadedDOMDocument.6.0) then the download of the document succeeds.
That being said I've made a few changes to your code, mostly to be more readable and make it fail visibly when the document load fails for some reason.
Note
the use of XPath
a helper function GetText() in place of blindly indexing into child nodes
the parseError check to make LoadXmlDocument fail non-silently
.
Option Explicit
Dim usdRate, x, currencies, curr
Set currencies = LoadXmlDocument("https://forex.boi.org.il/currency.xml")
usdRate = GetText(currencies, "//CURRENCY[CURRENCYCODE = 'USD']/RATE")
x = 1
For Each curr In currencies.getElementsByTagName("CURRENCY")
Response.Write "<p>" & GetText(curr, "NAME") & "</p>"
Response.Write "<p>" & GetText(curr, "UNIT") & "</p>"
Response.Write "<p>" & GetText(curr, "CURRENCYCODE") & "</p>"
Response.Write "<p>" & GetText(curr, "COUNTRY") & "</p>"
Response.Write "<p>" & GetText(curr, "RATE") & "</p>"
Response.Write "<p>" & GetText(curr, "CHANGE") & "</p>"
Response.Write "<p>___________________<br />" & x & "</p>"
x = x + 1
Next
' ----------------------------------------------------------------------
' loads an XML document from a URL and returns it
Function LoadXmlDocument(url)
Set LoadXmlDocument = CreateObject("MSXML2.FreeThreadedDOMDocument.6.0")
LoadXmlDocument.async = False
LoadXmlDocument.setProperty "ServerHTTPRequest", True
LoadXmlDocument.setProperty "SelectionLanguage", "XPath"
LoadXmlDocument.Load url
If LoadXmlDocument.parseError <> 0 Then
Err.Raise vbObjectError + 1, _
"LoadXmlDocument", _
"Cannot load " & url & " (" & LoadXmlDocument.parseError.reason & ")"
End If
End Function
' finds the first node that matches the XPath and returns its text value
Function GetText(context, xpath)
Dim node
Set node = context.selectSingleNode(xpath)
If node Is Nothing Then
GetText = vbEmpty
Else
GetText = node.text
End If
End Function
I just tried this on my machine. Try replacing
Server.CreateObject("MSXML2.FreeThreadedDOMDocument")
with
Server.CreateObject("Msxml2.DomDocument.6.0")
Edit
Server.CreateObject("MSXML2.FreeThreadedDOMDocument.6.0")
also seems to work
I have a vb6 project and i need to update a visual foxpro table from a recordset.My issue is when i try to update the table i get error msg:Command contains unregnized phrase/keywords.My problem is situated where the date field is concern.I dont know if i written the last portion of the code right.Here is my code:
rs2.Open "update transac set no_ot_1_5 = " & rs1.Fields("ovt1") & ", no_ot_2_0 = " & rs1.Fields("ovt2") & ", no_ot_3_0" _
& "= " & rs1.Fields("ovt3") & "where code = '" & rs1.Fields("emp_code") & "and transac.date = & trans.txtend &", cn1, adOpenDynamic, adLockPessimistic
Try this:
rs2.Open "update transac set no_ot_1_5 = " & rs1.Fields("ovt1") & ", no_ot_2_0 = " & rs1.Fields("ovt2") & ", no_ot_3_0" _
& "= " & rs1.Fields("ovt3") & " where code = '" & rs1.Fields("emp_code") & "' and transac.date = '" & trans.txtend &"'", cn1, adOpenDynamic, adLockPessimistic
It looks like you were missing a space before the WHERE keyword and you missed a single-quote after emp_code. It also looks like you had a problem with transac date.
If the solution from G Mastros is still not complete, it may be due to incorrect data type of a "Date" field. you may need to change to
transac.date = CTOD('" & trans.txtend &"') "
as if you are sending in a text string, but the date is of a DATE type field, you'll need to have it converted to a VFP recognized function... CTOD() is Convert Character String to a Date.