VBscipt date format - html

This is my query.
strSQL = "Select task,to_char(ddat,'dd/mm/yyyy') as ddat from task where guid = '"&lvGuid&"'"
'Response.write strSQL
objRS.Open strSQL, objConn
If objRS.RecordCount > 0 Then
strTask = objRS("task")
strDate = objRS("ddat")
Else
strTask = ""
strDate = ""
End If
This is the form that show that i wanted to display a text area if the people is finish their task after due date for asking the reason. But the problem is the if else statement cannot be run. The program not display the textarea when the person is over due date.
<form name="form1" method="post" action="taskconfirm.asp" >
<h2>Ticket : <input type="text" name="txtTask" value="<%=strTask%>" style="height:35px; font-size: 18pt; border:none;" readonly> </h2>
<p>Today's Date: <%=Date()%></p>
<p>Due Date: <%=strDate%></p>
<p>By reaching to this link, you have completed the ticket above. Please click the button below to confirm</p>
<br>
<!-- ASP IF ELSE CONDITION HERE DATE - OVERDUE -->
<%If Date() > strDate then %>
<%response.write("Please give a reason for ticket overdue :")%><br/>
<textarea type="text" name="txtreas" rows="4" cols="40" id="txtareaId"></textarea>
<%end if%>
<input type="submit" name="txtConfirm" value="Confirm" ">
</form>
I feel appreciate for anyone trying to help.Thanks a lot.

If the year comes last, VBScript interprets date literals as mm/dd/yyyy. Your SQL statement is formatting the date as dd/mm/yyyy, so it's going to get interpreted incorrectly (the months and days are going to get swapped).
For example, today is August 12, 2015. Your SQL statement is returning:
12/08/2015
But VBScript is seeing this date as December 8, 2015.
If you instead return the date as:
2015/08/12
Then VBScript won't be confused because the month always comes after the year when formatted with the year first (yyyy/mm/dd).

Related

How to display Success message after clicking Save in HTML page

I have an html form containing this code which runs on IIS:
<form action="http://server1/data.asp" method="POST">
Your Name: <input name="name" type="text">
<input value="Save" type="submit">
</form>
After user submits this form it runs the code in data.asp which displays a Success message with code to write to a text file (file1.txt):
Success!
<%
Dim fso
Dim tst
Set fso=Server.CreateObject("Scripting.FileSystemObject")
Set tst = fso.OpenTextFile("C:\Inetpub\wwwroot\data\file1.txt", 8, true)
tst.writeline "Name = " & Request.Form("name")
tst.writeline "" & Request.Form("")
tst.close
Set tst = Nothing
Set fso = Nothing
%>
This works but it just shows a page with Success! and stays there. What I'd really like is:
After user submits the form by clicking Save I'd like a little message box that says "Success" and remain on the same html page or go to a url I specify within the code.
I don't want to use Java or 3rd party extensions. This is an HTML page that runs the data.asp page on submit and I'd like it to stay that way if possible.
So how would I modify the html and/or data.asp page to do this?
You can do like this:
Response.Redirect "https://www.yoursite.com/thankyou.asp"
Instead of returning "Success!" as your response content you can return the form content you have above, this way you can use the same file for the GET and POST methods, with an condition on your asp logic to execute only on POST requests and return a success alert when the code is excuted successfully.
<form action="http://server1/index.asp" method="POST">
Your Name: <input name="name" type="text">
<input value="Save" type="submit">
</form>
<%
If (Request.Method = "POST") Then
Dim fso
Dim tst
Set fso=Server.CreateObject("Scripting.FileSystemObject")
Set tst = fso.OpenTextFile("C:\Inetpub\wwwroot\data\file1.txt", 8, true)
tst.writeline "Name = " & Request.Form("name")
tst.writeline "" & Request.Form("")
tst.close
Set tst = Nothing
Set fso = Nothing
response.write ("<script>alert('Success!');</script>")
End If
%>
Found the solution by adding an extra page to the mix (redir2form.asp):
in data.asp:
<%
Dim fso
Dim tst
Set fso=Server.CreateObject("Scripting.FileSystemObject")
Set tst = fso.OpenTextFile("C:\Inetpub\wwwroot\data\file1.txt", 8, true)
tst.writeline "Name = " & Request.Form("name")
tst.writeline "" & Request.Form("")
tst.close
Set tst = Nothing
Set fso = Nothing
%>
Response.Redirect "http://server1/redir2form.asp"
in redir2form.asp:
<%
response.write ("<script>alert('Success!');</script>")
%>
<meta http-equiv="refresh" content="1; url=http://server1/index.htm" />
Index.htm has the form action going to the data.asp page.
Not as neat as it could be but that's how I got it to work. After a user submits the form he gets the "Success!" message box and once they click OK they're redirected back to the form page.

if statement not executed in JSP scriptlet

i encountered the following problem. I have made a table in mysql named 'users' and i want to add users using JSP. The primary key is the Email and i want to check before adding another user if the email already exists. If the email already exists the users will not be added to the database and a message "email already exists" will appear.
I created ResultSet rs object and extracted the "Email" column into a String email using a while loop.Now, here comes the problem. Suppose i have a user with the "denis#yahoo.com" email. If i try to add an user with the exact same email an error will occur which means my if statement was ignored. I looked up in the debug mode for the variables email and Email and they had the exact same "denis#yahoo.com" and still the if statement was ignored.
<!-- file name: addUser.jsp -->
<%
String Email=request.getParameter("Email");
String Name = request.getParameter("Name");
String Adress = request.getParameter("Adress");
String Phone = request.getParameter("Phone");
if (Email != null)
{
jb.connect(); // connect to the database using JavaBean class
ResultSet rs;
rs=jb.seeTable("users");// rs gets first row of table
String email;
int a=1;
while(rs.next())
{
email=rs.getString("Email");
if(Email==email)
{
a=0;
jb.disconnect();
%>
<p> The email already exists</p>
<%
break;
}
}
if(a==1){
jb.addUser(Email,Name, Adress, Phone);
jb.disconnect();
%>
<p>Data has been added.</p>
<%
}
} else {
%>
<form action="addUser.jsp" >
Email: <input type="text" name="Email"><br>
Name: <input type="text" name="Name"><br>
Adress: <input type="text" name="Adress"><br>
Phone: <input type="text" name="Phone"><br>
<button type="submit" >Add User</button><br>
</form>
<%
}
%>
I use NetBeans IDE 8.2, and something that i think is odd appeared in the debug mode. One of the email i try to test appeared with bold characters meanwhile the other was not bold.
Why is my if statement ignored if i add an user with the exact same email of another? Please help me out!

How to call html form fields in vbscript dynamically in a loop

So I have an html form created in classic asp that has about 25 check boxes with different labels. The checkboxes are written to the page via a loop that grabs the label values from a table and each checkbox is named similarly ("decreason1","decreason2","decreason3",ect...) using a loop variable.
I use a vbscript at the end of the page to validate the data on the page before passing with a submit button. I need to make sure that at least one of the checkboxes is checked before submitting the form.
dim i, checkedvalue ;
checkedvalue = false
for i = 1 to 25
if document.rtftadd.decreason1.checked = true then
checkedvalue = true
end if
next
I need the "document.rtftadd.decreason1.checked" to change with the loop to decreason2, decreason3
I'm not sure how to go about doing that.
Any help would be greatly appreciated.
There are a few different ways to do this and if you are seeking a validation method prior to form submission then JavaScript may be a better solution.
However, in an effort to address your question using only ASP Server side code for VBScript and considering your question suggest that you do not care which box is selected nor how many are selected then the following code may be a working solution for you.
By looking at all of the elements sent via the form and checking if your form name (without number) exist then this same block of code will work even if you increase or decrease the number of check boxes you are validating for input.
<%#LANGUAGE="VBSCRIPT"%>
<%
dim checkedvalue
checkedvalue = false
if request("btn1") = "Submit" then
For each item in request.form
if instr(item,"decreason") > 0 then
checkedvalue = true
end if
next
response.write "Checked Value = " & checkedvalue & "<br><br>"
end if
%>
<html>
<head></head>
<body>
<form method="post" action="index.asp" name="rtftadd">
<input type="checkbox" name="decreason1"> Box 1<br>
<input type="checkbox" name="decreason2"> Box 2<br>
<input type="checkbox" name="decreason3"> Box 3<br>
<input type="checkbox" name="decreason4"> Box 4<br>
<input type="checkbox" name="decreason5"> Box 5<br>
<br>
<input type="submit" value="Submit" name="btn1">
</form>
</body>
</html>

Calling a vbscript funciton to update a SQL table from an HTML form generated on an asp-classic page

Having a hard time with updating a SQL table from an HTML form generated on an asp-classic page. The page dynamically creates a table based on a SQL query; I've added a form for the purpose of editing certain fields displayed in the table but have been unable to trigger the function (i.e. onclick) that the form button calls using the code below. I've tried multiple variations of the syntax used for calling the function via VBscript and am missing something entirely. I'm wondering if I'm trying something that can't be done in the asp-classic environment due to the server side code being used and the limitations that go with that (as well as my trying to use the same page to generate the results). I know the default behavior for the form is to refresh the page if I don't specify a different page. In the code below, I'm just trying to confirm the behavior before I add the SQL update statement to the function. (I'm typically only retrieving or inserting data for a web site - very little experience updating the data between a single page like this.)
<br>
<form method="POST" id="form" action="">
<table>
<tr>
<td>
<select name="state">
<%
'populate the dropdown selection for the state within the form
do until rs.eof
For each x in rs.fields
response.write "<option value=" & x.Value & ">" & x.Value & "</option>" & vbNewLine
next
rs.movenext
loop
%>
</select>
</td>
<td>
<select name="ps">
<option value="blank"></option>
<option value="prime">Primary</option>
<option value="secondary">Secondary</option>
</select>
</td>
<td>
<input name="emp_num" size="5" maxlength="5" rows="1" ></textarea>
</td>
<td>
<input type="submit" onclick="Go" value="Update record"/>
</td>
</tr>
</table>
</form>
<%
function Go() {
msgbox "test"
//additional SQL code would be included here once the function actually works
}
%>
<%
'close the DB connection
dbconn.close
%>
</body>
</html>
You're trying to mix server-side code with client-side code, and It Don't Work Like ThatTM.
Here's a very rough outline of how you could get information from the user, process it, and display it, all on the same asp page. Note the utter lack of JavaScript. :)
<html>
<head>
<title>My Page</title>
<link rel="stylesheet" type="text/css" href="css/stylestuff.css">
<%
Dim rs, sql, conn
Dim mylist, myval1, myval2, i
myval1 = Request.Form("val1")
myval2 = Request.Form("val2")
'- If the form hasn't been submitted yet, myval1&2 will be the special value Empty,
'- but you can treat them as a blank string ("") for all intents and purposes.
If Validate(myval1, myval2) = True and myval1 & myval2 <> "" Then
DoStuffWith myval1, myval2
End If
%>
</head>
<body>
<h1>My Page</h1>
<form method="post" action="">
<p>Select one: <select name="val1" size="1">
<%
ListStuff mylist
For i = 0 to UBound(mylist,1)
response.write "<option value='" & mylist(0,i) & "'"
If myval & "" = mylist(0,i) & "" Then response.write " selected"
response.write ">" & mylist(1,i) & "</option>"
Next
%>
</select></p>
<p>Write something here:
<input type="text" name="val2" value="<%=myval2%>" size="10"></p>
<p><input type="submit" name="btn" value="Submit"></p>
</form>
<%
If myval1 & myval2 <> "" Then
DisplayStuff myval1, myval2
End If
%>
</body>
</html>
<%
Sub ListStuff(L)
sql = "Select [...] From [...] Where [...]"
Set rs = Server.Createobject("ADODB.Recordset")
rs.Open sql, "connection string (or previously-opened connection object)", 1,2
If Not rs.EOF Then
L = rs.GetRows
Else
Redim L(1,0)
L(0,0) = 0 : L(1,0) = "missing!"
End If
rs.Close
Set rs = Nothing
End Sub
'---------------------------------
Function Validate(v1,v2)
dim f
f = True
If Not Isnumeric(v1) Then f = False
If Len(v2) > 10 Then f = False
Validate = f
End Function
'---------------------------------
Sub DoStuffWith(v1,v2)
'- table-creation (or whatever) code goes here
End Sub
'---------------------------------
Sub DisplayStuff(v1,v2)
'- display code goes here
End Sub
%>

VBA simple parse

I am using vba ( & internetexplorer object) to convert CSUIP to ISIN (these are financial security unique identification codes) from the following website http://www.isincodes.net/convert-cusip-to-isin.php.
I have so far created a vba code (in following order) that:
1. manipulates the US/CA dropdown box
2. inputs my CUSIP into the inputbox
3. clicks the "Covert"Button
Sub cusip_is2()
'declare variables
Set objie = CreateObject("internetExplorer.Application")
objie.Visible = True
'go to website
objie.navigate ("http://www.isincodes.net/convert-cusip-to-isin.php")
Do
DoEvents
Loop Until objie.readyState = 4
'input the CA in the country ID step1
objie.document.getelementbyID("country").Value = "CA"
'input 912796HQ5 in text box as desired CUSIP to convert
objie.document.getelementbyID("appendedInputButton").Value = "912796HQ5"
'press the button to convert
Set ElementCol = objie.document.getElementsByTagName("button")
For Each btnInput In ElementCol
btnInput.Click
Next btnInput
'wait until the pages loads (not sure if I need this)
Do
DoEvents
Loop Until objie.readyState = 4
'added extra few seconds incase HMTL document is updating
Application.Wait Now + TimeSerial(0, 0, 1)
'created userform to look at the data to see if I can find the converted CUSIP - WHICH I CANNOT (HELPPPPP!!!!)
Userfrom_Web_Code.Textbox_Webform.Text = objie.body.innerText
Userfrom_Web_Code.Show
'clean up and try again for the next failure LOL
objie.Quit
Set objie = Nothing
End Sub
From my research I know that I keep getting the source code but I want the DOM, this is where I am having trouble. Please see EXTRACT of source code on the website once I have inputted "CA" for country and the CUSIP "912796HQ5", and note that the id tag with results contains nothing.
<p>Enter a CUSIP and a correct ISIN will be calculated for you, if possible:</p>
<form class="form-inline">
<div class="input-append">
<select id="country" style="width:60px;">
<option value="CA">CA</option>
<option value="US" selected>US</option>
</select>
<input type="text" maxlength="9" class="span3" id="appendedInputButton">
<button type="button" class="btn">Convert</button>
</div>
</form>
<div id="results"></div>
<br><br>
</div>
<div class="span4">
<h4>What is a CUSIP?</h4>
<p>A CUSIP is a 9-character alphanumeric code which identifies a North American financial security.</p>
<p>
A CUSIP consists of three parts:<br>
• A six-character issuer code<br>
• A two-character issue number<br>
• A single check digit.<br><br>
For example: 780259206 (Royal Dutch Shell-A)
</p>
conversely when I check the inspect element which takes me to the "DOM" then I can see this under id results.
<div id="results" style="display: block;"><br>
<b>Strict Standards</b>: Non-static method Validate_CUSIP::validate() should not be called statically in <b>/home/isincode/public_html/action/c.php</b> on line <b>15</b><br>
<p class="text-success"><strong>Correct ISIN: CA912796HQ58</strong></p></div>
Can anyone please help me solve this problem in vba.
Note that I know that you can create an algorithm yourself in vba/excel to do the conversion of CUSIP to ISIN however I want to do this project in VBA to learn parsing. I am also very new to coding and have had limited exposure to please be kind and explain everything you suggest.
Please see if the following edit will suit you:
....
....
'added extra few seconds incase HMTL document is updated
Application.Wait Now + TimeSerial(0, 0, 2)
Dim ISIN As String
ISIN = Right(objie.document.getelementbyID("results").innerText,12) 'the 12 rightmost characters
Debug.Print "ISIN you are looking for is: " & ISIN
....
Edit the code to do something usefull with the ISIN-string