How to create a sub function with html code? - html

I'm trying to create a sub function in classic asp that shows Password: the text space ? Any suggestions?
Sub GetPassword()
response.write " Password:"
<input type="text" name="txtEmPwd" size="20" value="<%=strEmPwd%>"> 1st 3 chars of
last name <input type="text" name="txtFirst3" size="5" maxlength=3 value="<%=strFirst3%>">
end sub
I get an error where the greater than character
Microsoft VBScript compilation error '800a0400'
Expected statement

That's because you are writing html directly in server side code.
You have to add the html as a string, something like this:
Sub GetPassword()
dim html
html = "Password:"
html = html & "<input type='text' name='txtEmPwd' size='20' value='" & strEmPwd & "'> 1st 3 chars of last name "
html = html & "<input type='text' name='txtFirst3' size='5' maxlength='3' value='" & strFirst3 & "'>"
Response.Write html
end sub

Related

HTML, ASP - Contact Form Won't Work

This is my contact form that I want to connect to email upon form submission. I have researched on the net to do it but I cannot seem to run the codes.
I have two files where one is the html codes and another consists of the asp codes.
Need help on this please. Will appreciate your guidance.
<body>
<h3>Contact Form</h3>
<form name="form1" method="post" action="process.asp">
<label for="name">name</label>
<input type="text" id="name" name="name" placeholder="Your web id.."/>
<br><br>
<label for="deptID">Department ID</label>
<input type="text" id="deptID" name="departmentID" placeholder="Your department ID..">
<br><br>
<label for="issue">Issue</label>
<select id="issue" name="issue">
<option value="">Non-Availability of Test Points</option>
<option value="">Unable to Change Cycle Time Value</option>
<option value="">Unable to Retrieve Report</option>
</select>
<br><br>
<label for="subject">Additional Message</label>
<textarea id="subject" name="subject" placeholder="Write something.." style="height:200px"></textarea>
<br><br>
<input type="submit" value="Submit">
</form>
This is the process.asp page.
<%
formname = Request.Form("name")
formID = Request.Form("departmentID")
formquery = Request.Form("issue")
formsubject = Request.Form("subject")
Set Mail = Server.CreateObject("CDONTS.NewMail")
Mail.From = formname
Mail.FromName = formname
Mail.AddAddress "test#gmail.com"
Mail.Subject = "Form submitted from web site"
Bodytxt = "Details of Form submission :" & VbCrLf & VbCrLf
Bodytxt = Bodytxt & "Contact Name : " & formname & VbCrLf
Bodytxt = Bodytxt & "ID : " & formID & VbCrLf
Bodytxt = Bodytxt & "Query Entered : " & formquery & VbCrLf
Bodytxt = Bodytxt & "Subject Entered : " & formsubject
Mail.Body = Bodytxt
Mail.Username = "me#gmail.com"
Mail.Password = "password"
Mail.Host = "smtp.gmail.com"
Mail.Port = "587"
Mail.Send
Set Mail = Nothing
%>
Not sure whats going on with your code snippets but they look extremely incomplete, you need a heap more than that to join an ASP page to a backend set of code.
A standard setup using C# and ASP.Net is the following. Say my page is called "Default.aspx"
This would be my (As you called is HTML, but really you mean your ASP)
<%# Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
</div>
</form>
</body>
</html>
And then joined to this would be the C# ASP.Net
That would look something like this:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
}
What you have done above will never work, there is nothing referencing between the two files, your first piece of code is just plain html not ASP and there is nothing that defines your C# environment.
What I would suggest, get Visual Studio 2015 (Its free) and then click "New" and select ASP Website. Once you have done that click your new project and hit "Add Web Form" that will give you a good start, then you can start adding your form and code.
Caz

How to get value of HTML element with VB.net

I create html element from database :
Dim table As String = "<form method='POST'>"
table &= "<input type='textbox' value='123' id='txtText'/>"
table &= "<input type="sumbit" text='Submit' /></form>"
When i click button submit, I want get value textbox with VB.NET
You just need to use RUNAT = "SERVER"
<form method='POST'>
<input type='textbox' value='123' id='txtText'/>
<input runat="SERVER" type="hidden" name="txtHidden" value="123" />
</form>
You need to set the value to hidden text, use runat = "SERVER"and get the value on server-side.

Extract submit button value using jsoup

I have used HTTPClient to connect to a website and I can successfully access required data from the website using jsoup.
I have the following code from which I need to extract the submit button info.
<form method="POST" action="test.jsp" >
<font size="2">
<input type="hidden" name="num" id="num" value=123 >
<input type="hidden" name="iec" id="iec" value=456 >
<input type="submit" onclick=" return check();" value="Print" name="B1">
</font>
</form>
How can I access the value and name of the submit button?
You can access those values using the attr(String attribute) method of Element. For example:
String html = "<form method=\"POST\" action=\"test.jsp\" >"
+ "<font size=\"2\">"
+ "<input type=\"hidden\" name=\"num\" id=\"num\" value=123 >"
+ "<input type=\"hidden\" name=\"iec\" id=\"iec\" value=456 > "
+ "<input type=\"submit\" onclick=\" return check();\" value=\"Print\" name=\"B1\">"
+ "</font>"
+ "</form>";
Document doc = Jsoup.parse(html);
Element bttn = doc.select("input[type=submit]").first();
String value = bttn.attr("value"); // will be Print
String name = bttn.attr("name"); // will be B1

How to add a html image input to a form?

I would like users to submit images that are hosted on websites like imgur rather than uploading them onto my server.
How would I achieve this in html?
This is what my form looks like now:
response.write "<form action="""" method=""post"">" &_
"<input type=""hidden"" name=""stage"" value=""2"">" &_
"Title: " &_
"<input type=""text"" name=""title""><br>" &_
"Post: " &_
"<textarea id=""post"" name=""post""></textarea><br>" &_
"<select name=""category"">"
do until info.eof
response.write "<option value=""" & info(0) & """>" & info(1) & "</option>"
info.movenext
loop
response.write "</select>" &_
"Category <i>(pick one)</i><br>" &_
"<br>" &_
"<input type=""submit"" value="" add post "">" &_
"</form>"
What would I need to add to make this possible?
Just use ordinary text field and ask the user to put the image URL in there. Store this as raw string in the database and display it using ordinary <img> tag.
Form would have this:
response.write "<form action="""" method=""post"">" &_
"<input type=""hidden"" name=""stage"" value=""2"">" &_
"Title: " &_
"<input type=""text"" name=""title"" /><br />" &_
"Image: " &_
"<input type=""text"" name=""image"" /><br />" &_
...
And to display:
<img src="<%=rs("imageUrl")%>" />
If you absolutely must use input, try this:
background-image: url(...);
background-repeat: no-repeat;
background-position: <left|right>;
padding-<left|right>: <width of image>px;
It's usually a little easier to use a button with an img inside:
Text
However the browser implementations of button for submitting are inconsistent, as well as the fact that all button values are sent when button is used - which kills the "what button clicked" detection in a multi-submit form.

Checkbox ASP validation on submit

I have a form with 3 text fields and 3 checkboxes. I had implemented VB Script validation so if a user submits the form and leaves something empty, the user will get back to the form WHILE having the fields filled in already. That said, this is not working for the chackboxes.
this is the code I am using for the checkboxes I am doing code in the value""
<input type="checkbox" name="ClaimSection_ActivityProof" id="ClaimSection_ActivityProof" value="<%=Request.Form("ClaimSection_ActivityProof")%>" style="width:20px" />
<input type="checkbox" name="ClaimSection_InvoicesPayableByPartner" id="ClaimSection_InvoicesPayableByPartner" value="<%=Request.Form("ClaimSection_InvoicesPayableByPartner")%>" style="width:20px" />
<input type="checkbox" name="ClaimSection_InvoicesPayableByGFI" id="ClaimSection_InvoicesPayable" value="<%=Request.Form("ClaimSection_InvoicesPayable")%>" style="width:20px" />
To cut the sotry short, if a user checks 2 checkboxes, submits the form, and when he is redirected back to the form again, the checkboxes will remain checked. How I can do this please?
name ( or group ) the checkboxes by the same name, ( I assume they all are related ClaimSection matter)
So ,you can name them all as "ClaimSection". Just make sure you assign each one its own unique values!
Example;
<input type='checkbox' name='ClaimSection' value='ActivityProof'>
<input type='checkbox' name='ClaimSection' value='InvoicesPayableByPartner'>
<input type='checkbox' name='ClaimSection' value='InvoicesPayableByGFI'>
With this naming, if your user checks more than 2 checkboxes, you will get the corresponding values in a comma separated fashion.
So, if your user checks the last 2 checkboxes, you will get "InvoicesPayableByPartner,InvoicesPayableByGFI" in return.
Now that you know this, it won't be hard to set up a bunch of if branches to handle the checked vs not checked matter by comparing against what you got in the request("ClaimSection")
Something like the following can get you in the right direction..
dim submitted_ClaimSections
submitted_ClaimSections = request("ClaimSection")
submitted_ClaimSections = "," & submitted_ClaimSections & ","
//handle the ActivityProof checkbox checked_or_not =""
if instr(submitted_ClaimSections,"," & "ActivityProof" & ",")>0 then
checked_or_not = "checked"
end if
Response.write "<input type='checkbox' name='ClaimSection' value='ActivityProof' " & checked_or_not & "> ActivityProof"
//handle the InvoicesPayableByPartner checkbox checked_or_not =""
if instr(submitted_ClaimSections,"," & "InvoicesPayableByPartner" & ",")>0 then
checked_or_not = "checked"
end if
Response.write "<input type='checkbox' name='ClaimSection' value='InvoicesPayableByPartner' " & checked_or_not & "> InvoicesPayableByPartner"
//handle the InvoicesPayableByGFI checkbox checked_or_not =""
if instr(submitted_ClaimSections,"," & "InvoicesPayableByGFI" & ",")>0 then
checked_or_not = "checked"
end if
Response.write "<input type='checkbox' name='ClaimSection' value='InvoicesPayableByGFI' " & checked_or_not & "> InvoicesPayableByGFI"
I think you should post back your form data. Try following links:
http://www.motobit.com/tips/detpg_post-binary-data-url/
http://www.tek-tips.com/viewthread.cfm?qid=1281365
These links provides some example code sending form data with post method. Unfortunatly I haven't set up an IIS, so I couldn't try those examples. At the first view the idea can work.
The value attribute is not really relevent to making sure the checboxes retain their checked state on load / postback.
To do this, you need to check if they where checked on submit ("on" in request.form), if "on" then set checked="checked".
Example:
<%
if len(request.form("ClaimSection_ActivityProof")) > 0 then
ClaimSection_ActivityProof_Checked = " checked=""checked"""
else
ClaimSection_ActivityProof_Checked = ""
end if
%>
<input type="checkbox" name="ClaimSection_ActivityProof" id="ClaimSection_ActivityProof" <%=ClaimSection_ActivityProof_Checked %> style="width:20px" />
Hope that makes sense.
J.