Issues in declaring variables - vbscript

am trying to make a Petition form for a local company (A required project for graduation).
This is part of my page where I am facing troubles:
<FORM METHOD="POST" ACTION="InsertPetition.asp?EmpID=<%=Request.QueryString("EmpID")%>&BRANCH=<%=Session("BRANCH")%>" name=frmNewClaim>
<table>
<tr>
<td>From Date</td>
<td><SELECT name=cboFromDateDay>
<%For i = 1 To 31%>
<%if i=day(date()) then%>
<OPTION VALUE="<%=i%>" Selected="True"><%=i%></OPTION>
<%else%>
<OPTION VALUE="<%=i%>"><%=i%></OPTION>
<%end if%>
<%Next%>
</SELECT>
<SELECT name=cboFromDateMonth>
<%For i = 1 To 12%>
<%if i=month(date()) then%>
<OPTION VALUE="<%=i%>" Selected="True"><%=MonthName(i)%></OPTION>
<%else%>
<OPTION VALUE="<%=i%>"><%=MonthName(i)%></OPTION>
<%end if%>
<%Next%>
</SELECT>
<SELECT name=cboFromDateYear>
<%For i = Year(Date())-1 To Year(Date()) + 10%>
<%if i=year(date()) then%>
<OPTION VALUE="<%=i%>" Selected="True"><%=i%></OPTION>
<%else%>
<OPTION VALUE="<%=i%>"><%=i%></OPTION>
<%end if%>
<%Next%>
</SELECT>
</td>
<td><INPUT type="button" value="Submit" name=cmdSubmit></td>
</tr>
</table>
<SCRIPT LANGUAGE="VBSCRIPT">
Sub cmdClose_OnClick()
window.close
End Sub
Sub cmdSubmit_OnClick()
Dim fromdate2
Dim todate2
fromdate2="Trim(frmNewClaim.cboFromDateDay.Value) & "/" & Trim(frmNewClaim.cboFromDateMonth.Value) & "/" & Trim(frmNewClaim.cboFromDateYear.Value)"
todate2="Trim(frmNewClaim.cboToDateDay.Value) & "/" & Trim(frmNewClaim.cboToDateMonth.Value) & "/" & Trim(frmNewClaim.cboToDateYear.Value)"
Select case frmNewClaim.txtPTNGroup.Value
'If type is Birth
case 30
if DateDiff("d",fromdate2,todate2) > 45 then
msgbox "Days value exceeded the limit of days allowed!",16,"Data Entry Error"
frmNewClaim.txtPTNGroup.focus
Exit Sub
end if
case else
End Select
frmNewClaim.submit
End Sub
In this form, the user is required to insert day, month, year in the from date and the to date table row after selecting the type of the petition for example : Birth
In the script, i declared variables fromdate2 and todate2which are supposed to contain the date for example like this: "03/12/2015"
and in the select case case 30, the datediff function which will give me the amount of days between the fromdate2 todate2 and if it is less then 45 then a message box would appear (yes, i know it only works on IE) say the days exceeded the limit
The problem is when i test it and click submit nothing happens
Am pretty sure the error is in the fromdate2 todate2 variables
Help me and thank you in advance

I'm confused as to how you are trying to collect your form data. Unless I'm missing something you appear to be mixing server side and client side code.
Classic ASP is a server side technology, VBScript is the language it usually uses, (you can specify JavaScript if you prefer.)
Your subroutines are contained within <SCRIPT LANGUAGE="VBSCRIPT">. This means that it will be run client side - and as you are aware it will only work on IE
I think what you need to do is to first move your code to the server side. You can do this either by putting it inside <% %> delimiters, or by using <SCRIPT LANGUAGE="VBSCRIPT" runat="server">
Instead of onclick events use the request object to populate variables retrieved from your form fields, eg cboFromDateDay = Request.Form("cboFromDateDay")
Finally your vbs script seems designed to generate popup alerts. This wouldn't work with server side code. You could use Response.Write to have error messages appear within the text of your page.
If you desperately want popup alerts then you could have them triggered when the page loads, and put the code which triggers them within an asp conditional statement so that it only appears in the server output if certain conditions are met. I would suggest though that this is more trouble than it's worth

Related

Disable list if option selected

My code is partially working. The list gets disabled but it's not catching that I have selected "product1" and then enables the list. Anything else chosen should disable the list completely. List with ID product. So I guess it's something with my syntax for the option selected, not sure if thats the correct way to write it.
VBScript
'Disables or enables list based on selection
Function enabler()
For Each opt In document.GetElementByID("customer").Options
If opt.Selected = "product1" Then
document.GetElementByID("product").Disabled = False
Else
document.GetElementByID("product").Disabled = True
End If
Next
End Function
HTA
...
<select size="5" id="product" name="ListboxUserRole" onChange="SaveListboxUserRoleValue">
<option value="1" selected="selected">product1</option>
<option value="2">product2</option>
<option value="3">product3</option>
...
<select size="5" id="customer" name="ListboxCustomer" onChange="SaveListboxCustomerValue" value="1">
<option value="1" selected="selected">customer1</option>
<option value="2">customer2</option>
<option value="3">customer3</option>
<option value="4">customer4</option>
...
If I get it right, you need to enable the customer select when product1 is selected in product select, and disable if any other.
First of all, product select change event is linked to SaveListboxCustomerValue(). customer select disabling should be processed within SaveListboxCustomerValue(), replace <body onload="enabler()"> with just <body>.
IMO better to rework the algorithm to use the selectedIndex property of the product select object, the enabler() is not necessary then. Remove enabler(), and make changes to SaveListboxCustomerValue():
Sub SaveListboxCustomerValue()
' enable customer if the first item in product selected
customer.disabled = product.selectedIndex <> 0
' the rest part of the code
End Sub
Otherwise, if you want to keep the enabler(), then read about Option Object Properties. The condition you currently have always returns False, since boolean value never equals the string "product1". The code should be like this:
Sub enabler()
Dim opt
Dim match
For Each opt In product.options
match = opt.selected And opt.label = "product1"
If match Then Exit For
Next
customer.disabled = Not match
End Sub
enabler() should be called on customer change, add call to it:
Sub SaveListboxCustomerValue()
enabler()
' the rest part of the code
End Sub

How to get an index of specific text in dropdown using vbscript code(.vbs)?

I am working on vbscript. I am writing script for selecting value from dropdown.
In my scenario, I want to select a value from dropdown using the text which resides in option tag i.e <option>value<option>
Request you to provide code for selecting value in dropdown using value not by index of value.
Thank you in advance. Please reffer below html code for reference.
<select id="mydropdown" onchange="getServiceDetails();" name="mydropdown">
value="[]"
<option value="-1">Select value</option>
value="[]"
<option value="0920102049">value 1</option>
value="[]"
<option value="0060217015">value 2</option>
</select>
This will do it.
Sub SelectOptionByInnerHTML(selectID, text)
Dim list, opt
Set list = document.getElementById(selectID)
For Each opt In list
If opt.innerHTML = text Then
opt.selected = true
Exit Sub
End If
Next
End Sub
Usage:
SelectOptionByInnerHTML "mydropdown", "value 2"

how do i select datepicker using page-object-gem and jqueryui_widgets

I'm trying to use jqueryui_widgets combined with page-object-gem to test a datepicker, but I am failing on the first step.
on(HasADatepickerPage).the_datepicker = date
I get this error:
Watir::Exception::ObjectReadOnlyException: object is read only {:id=>"datepicker", :tag_name=>"input or textarea", :type=>"(any text type)"}
./features/step_definitions/datepicker_steps.rb:8:in `/^I enter the date "([^\"]*)"$/'
./features/has_a_datepicker.feature:8:in `When I enter the date "10/05/2015"'
has_a_date_picker_page.rb ( jqueryui_widgets example datepicker_page.rb )
class HasADatepickerPage
include PageObject
jqueryui_datepicker(:the_datepicker, :id => 'datepicker')
end
Questions:
What do I need to do prior to on(HasADatepickerPage).the_datepicker = date ?
What do I need to do prior to on(HasADatepickerPage).the_datepicker_select_day day ?
I cloned the jqueryui_widgets project, ran datepicker feature test, works fine. I modelled my solution as closely as I could to it.
I included snipets from my html page and the rest of the glory details I could think of below.
Thanks,
Tim
The Gory Details
my site html vs ( jqueryui_widgets example datepicker.html )
<div class="forms">
<div class="ajaxformitem" rel="Please select the number of passengers traveling">
<div class="ajaxformitem" rel="Please Enter the Date of Travel" style="background: transparent none repeat scroll 0% 0%;">
<div class="ajaxformitemleft">
<div class="ajaxformitemright">
<input id="datepicker" class="corner required hasDatepicker" type="text" placeholder="Pick Up Date" value="" readonly="true" name="PickUpTime[Date]"/>
<select id="hour" class="corner required" name="PickUpTime_Hour">
<select id="minute" class="corner required" name="PickUpTime[Mnute]">
</div>
</div>
ui-datepicker-div:
<div id="ui-datepicker-div" class="ui-datepicker ui-widget ui-widget-content ui-helper-clearfix ui-corner-all" style="position: absolute; top: 199px; left: 635.5px; z-index: 12; display: block;">
<div class="ui-datepicker-header ui-widget-header ui-helper-clearfix ui-corner-all">
<a class="ui-datepicker-prev ui-corner-all" title="Prev" onclick="DP_jQuery_1440799766008.datepicker._adjustDate('#datepicker', -1, 'M');">
<a class="ui-datepicker-next ui-corner-all" title="Next" onclick="DP_jQuery_1440799766008.datepicker._adjustDate('#datepicker', +1, 'M');">
<div class="ui-datepicker-title">
</div>
<table class="ui-datepicker-calendar">
<thead>
<tbody>
</table>
</div>
has_a_datepicker.feature - same as example
Feature: Using the JQueryUI Datepicker widget
Background:
Given I am on the has datepicker page
Scenario: Testing datepicker jqueryui_widgets
When I enter the date "10/05/2015"
And I select day "25"
Then the date should be "10/25/2015"
datepicker_steps.rb - the_datepicker vs (datepicker_one and datepicker_two)
Given(/^I am on the has datepicker page$/) do
visit(HomePage)
on(HomePage).select_radio_for 'From'
on(HomePage).select_service 'Airport'
end
When(/^I enter the date "([^\"]*)"$/) do |date|
on(HasADatepickerPage).the_datepicker = date
end
And(/^I select day "(\d+)"$/) do |day|
on(HasADatepickerPage).the_datepicker_select_day day
end
Then(/^the date should be "([^\"]*)"$/) do |day|
#on(DatepickerPage).datepicker_one.should == day
expect(on(HasADatepickerPage).the_datepicker).to eql day
end
Selecting a Date
If you look at the datepicker methods, all of the interactions with the calendar assume that the calendar is already displayed. If you look at the gem's test (features), you will see they always inputted the text field first, which opens the calendar. Only after that do the tests try to interact with the calendar.
However, since your text field is read-only, you cannot input the text field to trigger the popup. As a result, you need to click the text field. The datepicker accessor creates a {name}_element method for accessing the text field. Therefore, you can do:
page.the_datepicker_element.click
page.the_datepicker_select_day('15')
Setting a Date
The {name}= method for directly setting the date will not work for your control. The method simply types into the text field, which being read-only is not valid.
You seem to have 2 options:
Click the Next/Previous Month controls until you get the right month and then select the day.
Use JavaScript to input the text field directly.
Unless there are events the application excepts to be raised when inputting the date, I would suggest going with option 2. It is quicker and less error prone. While it does not mimic the user, testing the interactions within a jQuery widget should not be your responsibility.
date = '08/13/2015'
page.execute_script("arguments[0].value='#{date}';", page.the_datepicker_element)
If you really want to input the value like a user:
# These libraries are added to help with doing date comparisons
require 'date'
require 'active_support/time'
# The date you want to set
date = '12/13/2015'
# Open the calender
page.the_datepicker_element.click
# Determine if we need to navigate to a prior or future month
final_date = Date.strptime(date, '%m/%d/%Y')
current_date = Date.strptime(
"#{page.the_datepicker_month} #{page.the_datepicker_year}",
'%B %Y'
)
difference = (final_date.year * 12 + final_date.month) - (current_date.year * 12 + current_date.month)
# Navigate to the required month/year
if difference < 0
difference.abs.times { page.the_datepicker_previous_month }
else
difference.abs.times { page.the_datepicker_next_month }
end
# Select the day
page.the_datepicker_select_day(final_date.day.to_s)
As you can see, having to click the next/previous controls adds a lot of complexity.
Your ui-datepicker-div has: <input id="datepicker" readonly="true">
Watir won't let you send text to an element that is set to be readonly. Remove that attribute and this should work.

Angular dropdown/select required always says it is valid

So I have a dropdown and I am using angular to build it. Minutes is an array of numbers [0,1,2....59]. The filter is a simple filter that displays the digits from 0-9 as 00, 01... etc.
<select ng-model="addObj.StartMinute"
ng-options="m as m | pad2Digit for m in Minutes"
required
name="startMinute">
<option value="">-- select --</option>
</select>
My problem is that this ALWAYS reports being valid. I have removed the option in there that lets me customize the option used when no match is found, and that doesn't change it. I have tried setting StartMinute to null, -1 and undefined and still the select ALWAYS says it is valid.
I have found so far that the problem has to do with my using simple numbers rather than binding to objects. In cases where I am doing a dropdown with more a collection of objects, required validation is correctly detecting that nothing is chosen. I would have thought that setting the initial value on the above dropdown to null would work, but it isn't. So does anyone know how to use required validation on a dropdown that is bound to an array of numbers?
There must be something else on the project where it wasn't working making this not work because the raw jsfiddle I threw together to try to demo the problem works properly. If the initial value is null, then the validation does fail like I would expect.
HTML
<div ng-app="app">
<div ng-controller="ctrlDropdown">
<form name="testForm">
<select ng-model="number1"
ng-options="num for num in numbers"
required
name="ddl1">
<option value="">- select - </option>
</select>
<br/>failsValidation: {{testForm.ddl1.$error.required}}
</form>
</div>
</div>
JS
var app = angular.module("app",[]);
app.controller("ctrlDropdown",function($scope){
$scope.test = "wee";
$scope.number1 = null;
$scope.numbers=[1,2,3,4,5,6];
});
http://jsfiddle.net/NBhTT/

Select checkbox from excel with ruby

I would like to select a checkbox from an excel spreadsheet for a data driven test.
code for the checkbox:
Not Checked:
<input type="checkbox" class="greenopt" name="Accounts[0][greenopt]" id="" value="0">
Checked:
<input type="checkbox" class="greenopt" name="Accounts[0][greenopt]" id="" value="1">
I tried the following but get the error: Unable to locate element, using {:value=>"1"}
greenopt_check=worksheet.cells(rows,"O").value
browser.checkbox(:value => greenopt_check).set
this is kind of similar to my previous question regarding radio buttons
Select Radio buttons from excel with ruby
Please review the watir checkbox documentation. in that case you can checkbox.set or checkbox.clear depending on your goals.
You want to use something that is unique, and consistent/predictable to select elements
checkbox_class = worksheet.cells(rows,"A").value
puts 'retrieved checkbox_class from spreadsheet is:' + checkbox_class #for debugging, make sure you got the correct thing from the spreadsheet
browser.checkbox(:class => checkbox_class).set
or
checkbox_name = worksheet.cells(rows,"A").value
puts 'retrieved checkbox_name from spreadsheet is:' + checkbox_name #for debugging, make sure you got the correct thing from the spreadsheet
browser.checkbox(:name => checkbox_name).set

Resources