Checkbox ASP validation on submit - html

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.

Related

How to create a sub function with html code?

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

getElementsByTagName with multiple instances in HTML

having a bit of an issue with reading some HTML via VBA and can't seem to find any threads on here that have been able to solve issue. Here is a small chunk of the VBA, it does everything I need except for the last (most important) step which is to tell me whether or not a specific value exists within the HTML.
Do Until Not IE.Busy And IE.readyState = 4
DoEvents
Loop
promo = IE.Document.getElementById("formContent").getElementsByTagName("label")(1)
If InStr(promo.innerText, Range("E5").Value) = 0 Then
ActiveSheet.Range("D" & i) = "No"
Else
ActiveSheet.Range("D" & i) = "Yes"
End If
Next i
IE.Quit
Here's the HTML, I'm trying to check if the value in range E5 matches the value in one of the tags (which on will change depending on the value of E5)... I can't seem to get it to look through these tags and tell me if E5 matches... stumped.
<div id="formHeader">Personal Information:</div>
<div id="formContent">
Salutation:<br>
<label class="formResult">MR</label> <br>
First Name:<br>
<label class="formResult">John</label> <br/>
Middle Name:<br>
<label class="formResult">P</label> <br/>
Last Name:<br>
<label class="formResult">Smith</label> <br>
Preferred Name:<br>
<label class="formResult">Johnny</label> <br>
Date of Birth: <br>
<label class="formResult">Mar 31, 1985</label> <br/>
Gender:<br>
<label class="formResult">M</label> <br/>
Language:<br>
<label class="formResult">E</label> <br/>
</div>
<br/>
<div id="formHeader">Mailing Address:</div>
<div id="formContent">Address Type: <br/>
<label class="formResult">HOME</label> <br/>
Mail Consent: <br/>
<label class="formResult">Y</label> <br/>
Address 1: <br/>
<label class="formResult">101 Smith St</label> <br/>
Address 2: <br/>
<label class="formResult"></label> <br/>
City: <br/>
<label class="formResult">Happytown</label> <br/>
Any help would be appreciated, Thanks!
A simple loop to iterate all the label elements would be:
Dim promos As IHTMLElementCollection
Set promos = ie.Document.getElementById("formContent").getElementsByTagName("label")
For Each promo In promos
If InStr(promo.innerText, Range("E5").Value) = 0 Then
ActiveSheet.Range("D" & i) = "No"
Else
ActiveSheet.Range("D" & i) = "Yes"
End If
Next
However, you need to exit the loop if the value is found.
Logically, set the text to "No" and only change it to "Yes" if the value is found. Then Exit.
ActiveSheet.Range("D" & i) = "No"
Dim promos As IHTMLElementCollection
Set promos = ie.Document.getElementById("formContent").getElementsByTagName("label")
For Each promo In promos
If InStr(promo.innerText, Range("E5").Value) <> 0 Then
ActiveSheet.Range("D" & i) = "Yes"
Exit For
End If
Next

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.

html method=get not passing values to the next aspx page

i have simple html page with 3 textboxes.
<form id="form1" method=get action="http://mysite.com/default.aspx" runat="server">
<div>
<input id="name" type="text" value="Amy" />
<input id="email" type="text" value="amy#jf.com"/>
<input id="phone" type="text" value="2125552512" />
</div>
<input id="Submit1" type="submit" value="submit" />
</form>
Now when it loads default.aspx i have this code in the vb backend on page_load.
Dim tbName As TextBox = Page.FindControl("Name")
Dim tbPhone As TextBox = Page.FindControl("Phone")
Dim tbEmail As TextBox = Page.FindControl("Email")
If page.request("name") & "" <> "" AndAlso tbname IsNot Nothing Then
tbname.text = page.request("name")
End If
If page.request("email") & "" <> "" AndAlso tbEmail IsNot Nothing Then
tbEmail.text = page.request("email") & ""
end If
If page.request("phone") & "" <> "" AndAlso tbphone IsNot Nothing Then
tbPhone.text = page.request("phone") & ""
End If
The page loads but is these textboxes are empty. what am i doing wrong?
If you want to be able to access those controls serverside, you'll need to add the runat="server" attribute to each of them.
Also, the TextBox type you're referencing is the ASP.NET control, which you aren't using. What you'd be using, once you add the runat="server" tags is HtmlInputText.
You can use the TextBox type by using the TextBox ASP.NET control instead of the <input> elements:
<asp:TextBox ID="name" runat="server" Value="Amy" />
If all your ASP.NET page is doing is processing the request from the form, then there's no need to reference any textbox or input controls - it won't be possible since they don't exist as ASP.NET controls. All you need to do is read the values from Request.QueryString.
If the intent is for the inputs to be visible and/or editable once they're on the ASP.NET page, I'd recommend moving the HTML form into your ASP.NET page.
it is not like this that webform functionate.
First, your input in your form needs to be server control: ex <asp:TextBox runat="server" id="name" Text="value" />
Then in your codebehind file you do not have to go through Page.FindControl("YourInput") but only this.YourInput.Text

unable to pass boolean value

I have a form field/checkbox and am unable to pass the boolean value even though it is selected.
<input type="checkbox" name="IsContactValid"
id=" IsContactValid"
<cfif
ContactView.GetIsContactValid()>CHECKED
</cfif>>
that will be transmitted to the receiving form if the box is checked.
Kindly help.
You can give the check box a value:
<input type="checkbox" name="IsContactValid" value="1"
id=" IsContactValid"
<cfif
ContactView.GetIsContactValid()>CHECKED
</cfif>>
that will be transmitted to the receiving form if the box is checked.