Change event not firing, but seemingly defined? - events

<select name="category" onChange="SelectSubcategory();" style="width:250px" class="required"></select>
Sub Category
<select id="subcategory" name="subcategory" style="width:250px" class="required"></select>
Hi my webpage works apart from one of the drop downs. When I select the category, the subcategory doesn't fire.
function SelectSubcategory(){
// ON selection of category this function should fire
removeAllOptions(document.drop_list.subcategory);
addOption(document.drop_list.subcategory, "", "", "");
if(document.drop_list.category.value =="Hotel"){
addOption(document.drop_list.subcategory, "Room only", "Room only" ) ;
addOption(document.drop_list.subcategory, "Breakfast", "Breakfast" ) ;
addOption(document.drop_list.subcategory, "Breakfast & Evening", "Breakfast & Evening");
if(document.drop_list.category.value =="Chalet"){
addOption(document.drop_list.subcategory, "Chalet only", "Chalet only" ) ;
addOption(document.drop_list.subcategory, "Breakfast", "Breakfast" ) ;
addOption(document.drop_list.subcategory, "Breakfast & Carvery", "Breakfast & Carvery");
}
Could anyone suggest a good debugging tool as I am new to coding and web development and find error checking the most time consuming aspect. Many thanks

firebug will most likely help you discover any issues you are having. also, i think your javascript is incorrect. if think you need to use document.getElementByName.
instead of document.drop_list - use document.getElementByName('category') and document.getElementByName('subcategory')
i would modify the function like so (it also looks like you're missing some brackets:
function SelectSubcategory(){
// ON selection of category this function should fire
var cetegory = document.getElementByName('category');
var subcategory= document.getElementByName('subcategory');
removeAllOptions(subcategory);
addOption(subcategory, "", "", "");
if(category.value =="Hotel"){
addOption(subcategory, "Room only", "Room only" ) ;
addOption(subcategory, "Breakfast", "Breakfast" ) ;
addOption(subcategory, "Breakfast & Evening", "Breakfast & Evening");
}
if(category.value =="Chalet"){
addOption(subcategory, "Chalet only", "Chalet only" ) ;
addOption(subcategory, "Breakfast", "Breakfast" ) ;
addOption(subcategory, "Breakfast & Carvery", "Breakfast & Carvery");
}
}
i'd also have to see the addOption and removeAllOptions functions to ensure they are correct.
honestly, this could have been done a lot easier with jquery.

Related

SSRS: Month Date Expression in Header Text Box

I have the following Expression in the Header of a report and while the report is working fine, the expression returns #ERROR... 'Argument Month is not a valid value.'
= IIF
(
Month(Today) = 1,
"December, " & Year(Today) -1,
MonthName(Month(Today) -1) & ", " & Year(Today)
)
In January, I want the Text Box to display "December" & the Previous Year.
For all other months, I want to display the current Month Name and the current Year.
I would appreciate any help or pointers.
Thanks!!
I probably should have worked harder before posting my question but it was urgent and I wasn't sure I'd be able to find an answer.
This is how I was able to solve the problem:
= IIF
(
Month(Today) = 1,
MonthName(Month(DateAdd("M",-1,Today))) & " " & Today.AddYears(-1).Year,
MonthName(Month(DateAdd("M",-1,Today))) & " " & Today.AddYears(0).Year
)
Thanks!
You were close, I think this should work
=IIF(Month(Today) = 1, "December, " & Year(Today) -1, MonthName(Month(Today)) & ", " & Year(Today))

MS Access Reference to Recordset.Recordcount

I need to find out if there is a record in my
Main forms [frmShiftDay]
Subform [frmShiftMachinesSubform]
SubSubform [frmMachineOutputSubform]
and I can’t get it to reference at all. Thanks!
ElseIf Me!frmMachineOutputSubform.Form!frmMachineOutputSubform.Recordset.RecordCount = 0 Then
MsgBox "Product Name is missing", vbCritical + vbOKOnly, "Required Data!"
Me.frmShiftMachinesSubform.Form.frmMachineOutputSubform.SetFocus
Exit Sub
Try this ..
ElseIf Me.frmMachineOutputSubform.frmMachineOutputSubform.Recordset.RecordCount = 0 Then
I think that you are missing one last "form"
ElseIf Me.frmMachineOutputSubform.Form.frmMachineOutputSubform.Form.Recordset.RecordCount = 0 Then

Update a database record without refreshing a page. ASP VBscript

This requests for help follows a poorly worded request for help earlier (apologies).
I have two asp/vbscript pages. The second page (containing only <% vbscript %> is called when a form on the first page is submitted.
The code on the second page causes an update to a database record and is as follows (the fields are populated from querystring variables.):
Set MyConn=Server.CreateObject("ADODB.Connection")
MyConn.Open "dsn=xxx;uid=xxx;password=xxx;"
SQLString = "UPDATE dbo_tbl_printing_tempstore SET " & fieldPrefix & "has_text1 = 'YES', " & fieldPrefix & "text = '" & fieldUpdate & "' WHERE id = " & tempid & ""
MyConn.Execute(SQLString)
MyConn.Close
Set MyConn = Nothing
All the form submit does is to cause the database update to happen - nothing else.
The page then response.redirects back to the calling page. This causes a refresh and lot of data on the first page to be lost - this is what I'm trying to avoid.
Can someone please tell me how I can carry out the update without leaving and then refreshing the calling page please? I've been told Ajax can do this but I have no experience at all of using it.
Many thanks
First of all, change your code to use parameters so you will be protected against SQL Injection attack:
Set MyConn=Server.CreateObject("ADODB.Connection")
MyConn.Open "dsn=xxx;uid=xxx;password=xxx;"
SQLString = "UPDATE dbo_tbl_printing_tempstore SET " & fieldPrefix & "has_text1 = 'YES', " & fieldPrefix & "text = ? WHERE id = ?"
Set MyCommand = Server.CreateObject("ADODB.Command")
Set MyCommand.ActiveConnection = MyConn
MyCommand.CommandType = 1
MyCommand.CommandText = SQLString
MyCommand.Parameters.Append(MyCommand.CreateParameter("#text", 200, 1, 0, fieldUpdate))
MyCommand.Parameters.Append(MyCommand.CreateParameter("#id", 3, 1, 0, tempid))
MyCommand.Execute()
MyConn.Close
Set MyCommand = Nothing
Set MyConn = Nothing
Having this, the next step is adding hidden frame in the first page:
<iframe id="MyFrame" name="MyFrame" style="display:none;"></iframe>
And finally simply add target to your <form> tag like this:
<form action="SecondPage.asp" target="MyFrame">
That's it... now the form will be submitted "inside" the hidden frame, will still trigger the database update and won't cause any refresh.

QTP 10 - A function return deifferent results for same data in run and debug modes

I would extremely appreciate if anyone can suggest a solution for this.
I have a simple function that is is expecting for a browser to be opened on a page containing a web list that each value of it represents an account. When an account is selected it's products (if any) are displayed.
The functions goal is to retrieve an index of an account with products (the first to be found) or -1 if there are none.
The problem, which I can't figure out what is causing it, is that the function will return the correct result when I'm debugging it - meaning running the code step by step using F10, but will return a wrong result if I'll run regularly (F5). This behavior is consistent and the function retrieves the same result each time for each type of runs, meaning it's not a bug that just makes the function return a random answer.
This is the function:
' #return: a random account index with products if one exists
' otherwise returns -1
Public Function getRandomAccountWithProducts()
On Error Resume Next
Set Page1 = Browser("micclass:=browser").Page("micclass:=Page")
Set br = Browser("micclass:=Browser")
originalURL = br.GetROProperty("URL")
br.Navigate Environment.Value("SOME URL") & "REST OF URL"
br.Sync
Page1.WebList("name:=accountId").Select "#1"
br.Sync
' Display only products
Page1.WebRadioGroup("name:=name0").Click
Page1.WebList("name:=name1").Select "Display None"
Page1.WebList("name:=name2").Select "Display None"
Page1.WebButton("value:=Apply","visible:=True").Click
' Init
numOfAccounts = Page1.WebList("name:=accountId").GetROProperty("items count") - 1
If numOfAccounts < 1 Then
getRandomAccountWithProducts = -1
Reporter.ReportEvent micFail, "Number of accounts","There are no accounts. No account with products exists"
Exit Function
End If
hasProducts = false
accountIndex = 1
' Get account with products
While ((Not hasProducts) AND (accountIndex =< numOfAccounts))
' Return account if has products
If Page1.WebList("name:=webListName","index:=0","micclass:=WebList","visible:=True").Exist(5) Then
hasProducts = true
End If
If (Not hasProducts) Then
accountIndex = accountIndex + 1
Page1.WebList("name:=accountId").Select "#" & accountIndex
End If
Wend
br.Navigate originalURL
Set Page1= Nothing
Set br = Nothing
' If no account has products, report and exit, else return selected account index
If Not hasProducts Then
Reporter.ReportEvent micFail,"Accounts","No account has products."
getRandomAccountWithProducts = -1
Else
getRandomAccountWithProducts = accountIndex
End If
If Err<>0 Then
errorMessage = "Error number: " & Err.Number & vbNewLine & "Error description: " & Err.Description & vbNewLine & "Error source: " & Err.Source
Reporter.ReportEvent micFail,"Run Time Error",errorMessage
Err.Clear
End If
On Error GoTo 0
End Function
I'm running on Pentium 4, 3.2 GHZ, 2 GB RAM, Win XP, SP 3,IE 7, QTP 10.0 Build 513
Thanks!
Have you considered using the all items property?
AllItems = Page1.WebList("name:=accountId").GetROProperty("all items")
SplitItems = Split(AllItems, ";")
Found = False
For i = 0 To UBound(AllItems)
If AllItems(i) = "<product>" Then
Found = True
Exit For
End If
Next
Solution was found thanks to Jonty,
The problem was in the following section:
' Get account with products
While ((Not hasProducts) AND (accountIndex =< numOfAccounts))
' Return account if has products
If Page1.WebList("name:=webListName","index:=0","micclass:=WebList","visible:=True").Exist(5) Then
hasProducts = true
End If
If (Not hasProducts) Then
accountIndex = accountIndex + 1
Page1.WebList("name:=accountId").Select "#" & accountIndex
End If
Wend
The first time entered to the loop, the account really didn't have any products, so obviously none was recognized. So accountIndex was increased by one and the corresponding account was selected in the web list.
No here lies the problem. The select method caused a refresh in the page and the condition Page1.WebList("name:=webListName","index:=0","micclass:=WebList","visible:=True").Exist(5)
was evaluated before the web list was loaded thus, returning false.
I considered that option, but I thought (wrongly apparently) that the Exist(5) should do the trick, but it seems that it works differently than expected.
Thanks,
Alon

Using multiple Message Boxes in "if then" statement with VB

I am very new with programming and I have come across an issue in Visual Basic that I cannot figure out. Many forums and YouTube videos later I still do not have an answer.
I am using a nested selection structure and within it is two Message boxes. I cannot figure out how to get the second dialog result to trigger the elseif statement. It just skips over it. I believe since I have one variable declared for a dialog result it is checking both of them, but in this case I don't know how to declare only the second dialog result.
Here is the code so far.
Dim dblTotal As Double = 12
Dim strResponse As DialogResult
' Dialog box asking about a coupon and $2 coupon.
If MessageBox.Show("Does customer have a coupon?", "Coupon", MessageBoxButtons.YesNo) = vbYes AndAlso
MessageBox.Show("Does customer have a $2 coupon?", "Coupon", MessageBoxButtons.YesNo) = vbNo Then
lblTotal.Text = Convert.ToString(dblTotal - 4)
' Meant to be ran if statement is false. I dont Understand
' why it is skipping over and not executing.
' Is "dlgResult" reading the first one as well? How do I correct?
ElseIf strResponse = vbYes Then
lblTotal.Text = Convert.ToString(dblTotal - 2)
Else
lblTotal.Text = Convert.ToString(dblTotal)
End If
End Sub
I understand it would be easier to to code if the first message = vbNo, but I was trying to see if this way would work.
Thank you!!
Is this how you wanted it?
Dim dialog1 As DialogResult
Dim dialog2 As DialogResult
Dim dblTotal As Double = 12
dialog1 = MessageBox.Show("Does customer have a coupon?", "Coupon", MessageBoxButtons.YesNo)
dialog2 = MessageBox.Show("Does customer have a $2 coupon?", "Coupon", MessageBoxButtons.YesNo)
If dialog1 = DialogResult.OK Then
dblTotal = dblTotal - 2
End If
If dialog2 = DialogResult.OK Then
dblTotal = dblTotal - 2
End If
lblTotal.Text = Convert.ToString(dblTotal - 2)

Resources