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.
Related
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
I have an ASP page that displays a list of contacts with an edit button next to each contact. When i click on the edit button, it resubmits the form and displays detailed information about the selected contact. The control 'ContactType is a dropdown box with contact types in them. Another control is a checkbox 'CMP' that based on what value is selected in the ContactType control the checkbox is either enabled or disabled. I can get this functionality to work if the the dropdowns value is changed using a call to a javascript function on the OnChange event of the ContactType control but when the value is initially set, the onChange event does not fire. So if the contact that is selected has a contact type where the checkbox should be disabled when the form is rendered, the checkbox is not disabled. How do i set the 'CMP'controls disabled attribute to true/false based on the contact that was selected? Any help you can give me would be appreciated. This is classic ASP. I have attached the pertinent code below.
elseif Request("hdnSelect") = "True" then
'Select CustomerContact to edit
SQL = "dbo.GetCustomerContactInfobyContactID '" & sqlsafe(request("hdnWhichOne")) & "'"
set rsSelect = objDBConn.execute(SQL)
if not rsSelect.EOF then
ContactType = rsSelect("Contact_TypesID")
Name = rsSelect("Name")
Number = rsSelect("Number")
AltNumber = rsSelect("AltNumber")
EmailAddress = rsSelect("EmailAddress")
Notes = rsSelect("Notes")
FName = rsSelect("ContactFName")
LName = rsSelect("ContactLName")
Title = rsSelect("Title")
CMP = iif(rsSelect("CMP") = "True", "1","0")
//if the value of CMPEligable is false Disable the 'CMP' control otherwise enable it.
if (rsSelect("CMPEligable") = "False") then
CMP = 0
'this is where i need to set the 'CMP' controls disabled attribute to true
else
'this is where i need to set the 'CMP' controls disabled attribute to false
end if
end if
selectedID = request("hdnWhichOne")
bEditMode = True
elseif Request("hdnUpdate") = "True" then
Here is the HTML
<form method="post" action="AddCustomerContact.asp?action=submit" name="c">
<input type="hidden" name="sid" value="<%=Request("sid") %>" />
<input type="hidden" name="cid" value="<%=Request("cid") %>" />
<input type="hidden" name="hdnCancel" value="False" />
<input type="hidden" name="hdnSelect" value="False" />
<input type="hidden" name="hdnUpdate" value="False" />
<input type="hidden" name="hdnAdd" value="False" />
<input type="hidden" name="hdnDelete" value="False" />
<input type="hidden" name="hdnWhichOne" value="" />
<input type="hidden" name="hdnCMPEligable" value="" />
<table border="0" cellpadding="2" cellspacing="2" width="100%">
.
.
.
<input type="hidden" name="selectedID" value="<%= selectedID %>" />
<table border="0" cellpadding="2" cellspacing="2" width="100%">
<tr>
<td colspan="2" class="corpCopy"><br /><b>Edit Customer Contact</b></td>
</tr>
<tr>
<td>
<table border="0">
<tr>
<td align="right" width="180"><b><span class="corpCaption"><b>Contact Type:</b></span></b></td>
<td align="left">
<select name="ContactType" id="ContactType" onchange="javascript:displayCMP(this.selectedIndex);">
<!--onchange="javascript:saveSalesChannel(this);">-->
<option value="">* Select *</option>
<%
dim contacttypeid
If request("sid") <> "" Then
SQL = "dbo.proc_Contact_Types_GetbyselectedID " & selectedID
set rscontactTypes = objDBConn.execute(SQL)
if not rscontactTypes.EOF then
contacttypeid = rscontactTypes("Contact_TypesID")
end if
End If
If contacttypeid = "" Then
contacttypeid = ""
end if
SQL = "dbo.proc_Contact_Types_GetAll"
set rsCT = objDBConn.execute(SQL)
Do While Not rsCT.EOF
if rsCT("isActive") = True then
Response.Write "<option value='" & rsCT("id") & "-" & rsCT("CMPEligable") & "'"
if rsCT("id") = contacttypeid then
Response.Write " selected"
end if
Response.Write ">" & rsCT("Type") & "</option>"
else
if rsCT("id") = contacttypeid then
Response.Write "<option value='" & rsCT("id") & "-" & rsCT("CMPEligable") & "' selected>" & rsCT("Type") & "</option>"
end if
end if
rsCT.movenext
Loop
rsCT.Close
set rsCT = nothing
%>
</select>
</td>
.
.
.
.
<tr>
<td align="right" valign="top"><b><span class="corpCaption"><b>CMP:</b></span></b></td>
<td align="left" valign="top">
<input type="checkbox" name="CMP" id="CMP" class="CMP" value="1" <% if CMP = 1 then response.write "checked='Checked'" end if %> />
</td>
</tr>
.
.
.
I was able to figure out my own answer to my own question. i added a hidden control that when the contact is selected and a stored proc is run to get the detail information on the contact, i set the hidden controls value based on the CMPEligable flag returned from the query.
SQL = "dbo.GetCustomerContactInfobyContactID '" & sqlsafe(request("hdnWhichOne")) & "'"
set rsSelect = objDBConn.execute(SQL)
if not rsSelect.EOF then
ContactType = rsSelect("Contact_TypesID")
Name = rsSelect("Name")
Number = rsSelect("Number")
AltNumber = rsSelect("AltNumber")
EmailAddress = rsSelect("EmailAddress")
Notes = rsSelect("Notes")
FName = rsSelect("ContactFName")
LName = rsSelect("ContactLName")
Title = rsSelect("Title")
CMP = iif(rsSelect("CMP") = "True", "1","0")
if (rsSelect("CMPEligable") = "True") then
hdnCMPEligable = "True"
else
CMP = 0
hdnCMPEligable = "False"
end if
end if
Then in my html i when the form is rendered, i check the value of the hidden control and set the disabled property appropriately.
<td align="left" valign="top">
<input type="checkbox" name="CMP" id="CMP" class="CMP" value="1" <% if CMP = 1 then response.write "checked='Checked'" end if %> <% if hdnCMPEligable = "False" then response.write " disabled='True' " end if %> />
</td>
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
I am trying to create a list of radio buttons that when the user selects one option a different form is displayed than if they select another radio button. For example, if they select "Add category" the associated form will display but if they select "delete category", a form allowing them to delete the category would display.
At the moment I am using a variable called "stage" and moving through the process by setting stage to different numeric values as they are passed through the hidden data of each form. Unfortunately I cannot get it to display anything other than the form in stage 2.
<% option explicit %>
<html>
<head>
</head>
<body>
<!--#include file="dbconn.asp"-->
<!--#include file="header.asp"-->
<div class="content">
<div class="content-inner container_12">
<div class="wrapper prefix_2 grid_8 suffix_2">
<%
dim stage, SQL, info
stage = request.form("stage")
if stage = "" then stage=1
'------------------------------------------------------------------
if stage = 1 then
'------------------------------------------------------------------
' 0 1
SQL="select ID, category "&_
"from categorytable "&_
"order by category DESC"
set info=conn.execute(SQL)
if info.eof then
response.write "<p>There are no categories</p>"
end if
'--- create a radio-button list of the current posts
response.write "<form id=""categoryedit""action=""category.asp"" method=""post"">" &_
"<input type=""hidden"" name=""stage"" value =""2"">"&_
"<label for=""addcategory"">Add Category</label>"&_
"<input id=""addcategory"" type=""radio"" name=""addcategory"" value=""stage = 2""><br>" &_
"<label for=""deletecategory"">Delete Category</label>"&_
"<input id=""deletecategory"" type=""radio"" name=""deletecategory"" value="" stage = 4""><br>" &_
"<label for=""editcategory"">Edit Category</label>"&_
"<input id=""editcategory"" type=""radio"" name=""editcategory"" value="" stage = 6""><br>" &_
"<input class=""button"" type=""submit"" value=""Select"">" &_
"</form>"
'------------------------------------------------------------------
elseif stage = 2 then
'------------------------------------------------------------------
response.write "<form action=""category.asp"" method=""post"">" &_
"<input type=""hidden"" name=""stage"" value =""3"">"&_
"<label for ""category"">New Category</label>"&_
"<input type=""text"" id=""category"" name=""newcategory"" required><br>"&_
"<input class=""button"" type=""submit"" value=""Add Category"">"&_
"</form>"
'------------------------------------------------------------------
elseif stage = 3 then
'------------------------------------------------------------------
dim category
category = request.Form("newcategory")
sql = "insert into categorytable (category) "&_
"values ('" & category & "')"
conn.execute sql
response.write "<p>New Category added.</p>"
'------------------------------------------------------------------
elseif stage = 4 then
'------------------------------------------------------------------
' 0 1
SQL="select ID, category "&_
"from categorytable "&_
"order by category DESC"
set info=conn.execute(SQL)
response.write "<form action=""category.asp"" method=""post"">" &_
"<input type=""hidden"" name=""stage"" value =""5"">"&_
"<label for ""category"">Delete Category</label>"
do
response.write "<label for=""radio""></label>"&_
"<input id=""radio"" type=""radio"" name=""categorytobedeleted"" value=""" &_
info(0) & """>" &_
info(1) & "<br>"
info.movenext
loop until info.eof
response.write "<input class=""button"" type=""submit"" value=""Delete Category"">"&_
"</form>"
'------------------------------------------------------------------
elseif stage = 5 then
'------------------------------------------------------------------
dim deleteCategory
deleteCategory = Request.Form("categorytobedeleted")
sql = "delete * from categorytable where ID= "& deleteCategory
conn.execute(sql)
response.write "<p>Category deleted.</p>"
'------------------------------------------------------------------
elseif stage = 6 then
'------------------------------------------------------------------
' 0 1
SQL="select ID, category "&_
"from categorytable "&_
"order by category DESC"
set info=conn.execute(SQL)
response.write "<form action=""category.asp"" method=""post"">" &_
"<input type=""hidden"" name=""stage"" value =""7"">"&_
"<label for ""category"">Edit Category</label>"
do
response.write "<label for=""radio""></label>"&_
"<input id=""radio"" type=""radio"" name=""categorytobeedited"" value=""" &_
info(0) & """>" &_
info(1) & "<br>"
info.movenext
loop until info.eof
response.write "<input class=""button"" type=""submit"" value=""Edit Category"">"&_
"</form>"
'------------------------------------------------------------------
elseif stage = 7 then
'------------------------------------------------------------------
dim record_num
record_num=Request.Form("categorytobeedited")
if record_num="" then response.redirect "?pg=category"
' 0 1
SQL= "SELECT categorytable.ID, category "&_
" FROM CategoryTable"&_
" WHERE categorytable.ID= "&record_num
set info=conn.execute(SQL)
%>
<form action="category.asp" method="post">
<input type="hidden" name="stage" value="8">
<input type="hidden" name="categorytable.ID" value="<% =record_num %>">
<label for="category">Category</label>
<input id="category" type="text" name="title" value="<% =info(1) %>"><br>
<input id="edit" class="button" type="submit" value="Edit">
</form>
<%
'------------------------------------------------------------------
elseif stage = 8 then
'------------------------------------------------------------------
dim addcategory
addcategory = request.form("categorytable.ID")
sql="update categorytable set category='"& addcategory & "'" &_
"where categorytable.ID= "& addcategory
conn.execute sql
response.write "<p>Category edited.</p>"
'------------------------------------------------------------------
end if ' stage
'------------------------------------------------------------------
if stage = 8 then
response.write "Show Categories"
end if
conn.close
%>
</div>
</div>
</div>
<!--#include file="footer.asp"-->
</body>
</html>
This section looks wrong. A group radio buttons should share the same variable name. Change the name of your radio buttons so they are ALL named "stage". Remove the hidden field with the name "stage" and set the values of the radio buttons to just numeric values.
response.write "<form id=""categoryedit""action=""category.asp"" method=""post"">" &_
"<input type=""hidden"" name=""stage"" value =""2"">"&_
"<label for=""addcategory"">Add Category</label>"&_
"<input id=""addcategory"" type=""radio"" name=""addcategory"" value=""stage = 2""><br>" &_
"<label for=""deletecategory"">Delete Category</label>"&_
"<input id=""deletecategory"" type=""radio"" name=""deletecategory"" value="" stage = 4""><br>" &_
"<label for=""editcategory"">Edit Category</label>"&_
"<input id=""editcategory"" type=""radio"" name=""editcategory"" value="" stage = 6""><br>" &_
"<input class=""button"" type=""submit"" value=""Select"">" &_
"</form>"
Correct code should look something like this
<form id="categoryedit" action="category.asp" method="post">
<label for="addcategory">Add Category</label>
<input id="addcategory" type="radio" name="stage" value="2"><br>
<label for="deletecategory">Delete Category</label>
<input id="deletecategory" type="radio" name="stage" value="4"><br>
<label for="editcategory">Edit Category</label>
<input id="editcategory" type="radio" name="stage" value="6"><br>
<input class="button" type="submit" value="Select">
</form>
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.