I have a checkbox called "cbBatch" on one of my pages. When i check the box and submit the form, "cbBatch" is stored with a value of 1. On the next page, I need cbBatch to be "checked" if the value in the corresponding database field is "1". If it's 0, then unchecked. I have attempted to write it like this:
<input type="checkbox" name="cbBatch<%=vIndex%>" id="cbBatch<%=vIndex%>" value="<%If RS("batch") = 1 Then Response.Write " checked" End If%>">
my database field is an integer, fyi. and this isn't working. I did a response.write to verify that the value of the checkbox is indeed 1, and it is. so i don't understand why this isn't working. What am I missing?
Thanks!
Couple of things.
The recordset doesn't return integers, unless you explicitly cast the returned value to an integer.
Secondly, to set a checkbox to checked you don't set the value to checked. You just set the "checked" property.
This should work for you:
<input type="checkbox" name="cbBatch<%=vIndex%>" id="cbBatch<%=vIndex%>"<%If "" & RS("batch") = "1" Then Response.Write " checked" End If%>>
Related
I have a parameter that is multi-select. When the user selects more than one value the value "Multiple" should appear. When the user only selects one value then only that value should appear. This is for a textbox in the Header of the report.
My expression is as below:
="Division: " & IIF(Parameters!Division.Count > 1, "Multiple", Parameters!Division.Value)
I think the following expression will overcome your issue;
="Division: " & IIF(Parameters!Division.Count > 1, “Multiple Years”, JOIN(Parameters!Year.Value, ", "))
Hi i need to enter a car reg into the below input box:
<input type="text" class="form-control text-uppercase car-registration__input ng-pristine ng-invalid ng-invalid-required ng-valid-maxlength ng-touched"
data-ng-model-options="{updateOn: 'blur'}"
data-ng-keyup="inputChange=true; regnumberNotFound=false; carLookupButtonSubmitted=false" data-motor-regnumber=""
data-msm-answer-store-key="" data-ng-required="true"
data-msm-answer-store-action="{'regnumberUpdate': {'targets': [{}]}}"
data-msm-error-tracking-view-change="" id="regnumber" name="regnumber"
data-ng-model="regnumber" maxlength="10" data-msm-field-interaction-events="click"
data-ng-change="returnedUserCheck()" required="required">
using the following i can enter the value but the box doesn't think that there is anything there and therefore wont validate and i have to manually click inot the text box:
IE.document.all("regnumber")(1).innerText = Reg
IE.document.all("regnumber")(1).setCapture
IE.document.all("regnumber")(1).Click
IE.document.all("regnumber")(1).releaseCapture
IE.document.getElementsByTagName("BUTTON")(7).Click
Any help would be greatly appreciated
Try replacing:
IE.document.all("regnumber")(1).innerText = Reg
With:
IE.document.all("regnumber")(1).value = Reg
The value attribute specifies the value of an <input> element
The value attribute is used differently for different input types:
For "button", "reset", and "submit" - it defines the text on the
button
For "text", "password", and "hidden" - it defines the initial
(default) value of the input field
For "checkbox", "radio", "image" -
it defines the value associated with the input (this is also the value
that is sent on submit)
Note: The value attribute cannot be used with <input type="file">.
Edit:
It looks as if it's using angular to check the value has changed.
Specifically, this attribute on the input element:
data-ng-keyup="inputChange=true; regnumberNotFound=false; carLookupButtonSubmitted=false"
It appears that you would need to also trigger a keyup event, which will likely require something like the following:
IE.document.all("regnumber")(1).Focus()
IE.document.all("regnumber")(1).Value = Reg + "." 'extra full stop will be removed on the next line
SendKeys "{BS}"
However, SendKeys is usually frowned upon unless absolutely necessary.
It may be worth trying to "trick" the form to recognise the value change by forcing the blur event to occur.
This can be done by setting the focus to the input box, then setting the focus to another element, as follows:
IE.document.all("regnumber")(1).Focus()
IE.document.all("regnumber")(1).innerText = Reg
IE.document.getElementsByTagName("BUTTON")(7).Focus()
IE.document.getElementsByTagName("BUTTON")(7).Click
I'd recommend trying this suggestion before going down the SendKeys route
I was having similar trouble with a form and I found this:
VBA interaction with internet explorer
Which helped me solve the exact same type of problem!
The trick was to use
Public Declare Function SetForegroundWindow Lib "user32" (ByVal HWND As Long) As Long
At the top of the Module, then modify your code to the following:
Dim HWNDSrc As Long
HWNDSrc = ie.HWND
SetForegroundWindow HWNDSrc
IE.document.all("regnumber")(1).Focus()
IE.document.all("regnumber")(1).Value = Reg + "." 'extra full stop will be removed on the next line
Application.SendKeys "{BS}"
I'm trying to simply check "Yes" on an internet explorer input checkbox if the user clicks "Yes" to a MsgBox popup, or do nothing if the user clicks "No" on the MsgBox. No matter what I try, the code just doesn't seem to click the button I want it to click.
My code is as follows:
strPrompt = "Please look to see if this client has a valid brokerage account available for enrollment. Would you like to enroll this client in FRT service and submit a ticket?"
strTitle = "User Input Required"
iRet = MsgBox(strPrompt, vbYesNo, strTitle)
If iRet = vbYes Then
Enrollment_Button = objIE.document.getElementsById("classActionFlagReq")
Enrollment_Button.Value = "Y"
Else
MsgBox "No"
End If
I will also include the HTML source where the Yes and No buttons are contained:
<SPAN class=radio2>
<input name="classActionFlagReq" class="radio2" type="radio" value="Y"></input>
</span>
<SPAN class=radio2>
<input name="classActionFlagReq" class="radio2" type="radio" value="N"></input>
</span>
Where am I going wrong?
Updated Edited Code:
iRet = MsgBox(strPrompt, vbYesNo, strTitle)
If iRet = vbYes Then
Set Enrollment_Button = objIE.document.getElementById("classActionFlagReq")
Enrollment_Button.Checked = True
Else
MsgBox "No"
End If
You've got a few issues.
It's getElementById(), not getElementsById().
getElementById() returns an object. Use Set.
Set Enrollment_Button = objIE.document.getElementById("classActionFlagReq")
Use the Checked property to set a checkbox or radio button, not Value="Y".
Enrollment_Button.Checked = True
You're using the same name for both radio buttons, which is fine (that's how you define a radio "group") but if you want to access an individual radio button (so that you can select it), you need to assign a unique ID (or use a different selector method, like getElementsByName).
The properties name and id aren't interchangeable. You don't have any element with an id equal to "classActionFlagReq", so getElementsById is not finding any elements.
Note that id is unique, so you won't just be able to set both inputs to the same id like you did with the names.
Set ieRadio = objIE.document.all
ieRadio.Item("classActionFlagReq")(1).Checked = True
This solved my issue!
I'm trying to find a way to do the following:
I want to have two different formats for a certain text box. To do so, I've done the following: User types one or two digits in a form text box(who's input and format are both "#,0;0;_") and has "yes/no" box on the right of that number field which asks if it's "kg per bag"(so by default it's the other measurement unit which is Percentages), then an OnLoad event is fired when viewing the report for that form, which checks if the yes/no value is yes or no. If "yes" then the format is set to "#.0 & " kg/bag"", if no it's set to "#.0 & " %"".
I will have to additionally divide by 100 when percentages are the ones picked, but first I want the whole thing to work... Which I still can't do!
Sadly, I'm nowhere near getting it to work... Here is my current macro on the onload event of the report, which is marked as not valid expression:
Link to the image on Imgur
Or here is the MacroBuilder Code:
<?xml version="1.0" encoding="UTF-16" standalone="no"?>
<UserInterfaceMacros xmlns="http://schemas.microsoft.com/office/accessservices/2009/11/application"><UserInterfaceMacro For="Report" Event="OnLoad"><Statements><ConditionalBlock><If><Condition>[yn]=False</Condition><Statements><Action Name="SetValue"><Argument Name="Item">[Text0].[Format]</Argument><Argument Name="Expression">#,0 & " kg/bag"</Argument></Action></Statements></If><Else><Statements><Action Name="SetValue"><Argument Name="Item">[Text0].[Format]</Argument><Argument Name="Expression">#,0 & " %"</Argument></Action></Statements></Else></ConditionalBlock></Statements></UserInterfaceMacro></UserInterfaceMacros>
Which is displayed as:
If [yn]=False Then
SetValue
Item = [text0].[format]
Expression = #,0 & " kg/bag"
Else
SetValue
Item = [text0].[format]
Expression = #,0 & " %"
End if
Can anyone give me a hint on where to go with this? Thank you!!
P.S. Comma is my decimal separator in regional settings!
You don't really need to change format only concatenate the numeric value with unit (kg/bag or %).
Using VBA, try the following code in the OnLoad event (I am assuming the recordsource field behind the text0 control is called the same -text0):
If Forms!yourformname![yn] = False Then
Reports!yourreportname!text0 = Me.text0 & " kg/bag"
Else
Reports!yourreportname!text0 = (Me.text0)/100 & "%"
' ALTERNATIVELY: Reports!yourreportname!text0.Format = "percent"
End If
Alternatively in the OnLoad event, use an embedded macro or call an external macro with the following one action (if/then changed into the IIF function):
SetValue
Item: text0
Expression: =IIF(Forms!yourformname![yn] = False, text0 & " kg/bag", text0/100 & "%")
I am running into a problem with my vbscript code. My HTML code looks like this
<input type='checkbox' name='DisplayRow' id='DisplayRow1' />
<input type='checkbox' name='DisplayRow' id='DisplayRow2' />
<input type='checkbox' name='DisplayRow' id='DisplayRow3' />
This is done because above there is another checkbox that calls a javascript function that will check or uncheck all of the "DisplayRow" checkboxes. The javascript function uses getElementsByName to return all of the checkboxes named "DisplayRow".
When the form's submit button is clicked the action sends it to an ASP page (classic ASP) that grabs all of the objects on the calling form by using the Request.Form command. The Request.Form command looks at the "name" attribute, not the "id" attribute of the object.
This seems to be working fine for all of the other form objects. When it gets to the checkboxes because the "name" attribute uses the same name for all of the check boxes it returns an array. The individual checkboxes can be accessed like this:
Request.Form("DisplayRow")(x)
Where x references the individual checkbox in the array.
If the checkboxes are checked I can loop through the array without any problems. If 1 or more or all of the checkboxes are unchecked then when the code references the first checkbox in the array that is unchecked the page crashes. Nothing is executed after the Request.Form command fails.
I have tried enclosing the Request.Form("DisplayRow")(x) in an IsNull function in an If statement but it still takes the program down.
Has anyone else ran into this and found a work around?
Edit
For some reason stackoverflow is not letting me add more than one comment.
#Cory. Thanks for the information
#jwatts1980. Count works but it does not let me know which of the checkboxes are checked. If the count is greater than 0 I can loop through them but if the first one is unchecked I am right back where I started with a crashed page.
You cannot do it this way because unchecked checkboxes will not be submitted in the post, only the checked ones.
I would approach this differently:
First I would add a value attribute to the checkboxes, as so:
<input type='checkbox' name='DisplayRow' id='DisplayRow1' value="1" />
<input type='checkbox' name='DisplayRow' id='DisplayRow2' value="2" />
<input type='checkbox' name='DisplayRow' id='DisplayRow3' value="3" />
Notice the value is the same as the index, this will be needed in the code.
Next I would use .Split() to gather the checkboxes selected in an array, since the values will come in as a string separated by comma, ie: 1,2,3 to your .Form() value.
Rows = Request.Form("DisplayRow")
'check if any are selected first
If Rows <> "" Then
'make an array with each value selected
aRows = Split(Rows,",")
'loop through your array and do what you want
For i = lBound(aRows) to uBound(aRows)
Response.Write "DisplayRow" & aRows(i) & " was Selected."
Next
End If
This way you only process the results for the one's selected, and ignore the others.
I've always found this essential for my library...
'GetPostData
' Obtains the specified data item from the previous form get or post.
'Usage:
' thisData = GetPostData("itemName", "Alternative Value")
'Parameters:
' dataItem (string) - The data item name that is required.
' nullValue (variant) - What should be returned if there is no value.
'Description:
' This function will obtain the form data irrespective of type (i.e. whether it's a post or a get).
'Revision info:
' v0.1.2 - Inherent bug caused empty values not to be recognised.
' v0.1.1 - Converted the dataItem to a string just in case.
function GetPostData(dataItem, nullVal)
dim rV
'Check the form object to see if it contains any data...
if request.Form = "" then
if request.QueryString = "" then
rV = nullVal
else
if request.QueryString(CStr(dataItem))="" then
rV = CStr(nullVal)
else
rV = request.QueryString(CStr(dataItem))
end if
end if
else
if request.Form(CStr(dataItem)) = "" then
rV = CStr(nullVal)
else
rV = request.Form(CStr(dataItem))
end if
end if
'Return the value...
GetPostData = rV
end function
To use the function you simply pass in the form or query string item you're looking for and what to replace empty values with...
Dim x
x = GetPostData("chkFirstOne", false)
You can keep using your existing code by adding a single condition:
If Request.Form("DisplayRow").Count > 0 Then
'your code here
Else
'consider adding message saying nothing was selected
End If