jquery code integrated in backbone code
I have a js file which has backbone related code, and in it I want to place jquery code.
And to be more specific,,,in the app(booking) I am building the user will have
to make a choice of a staff member from a dropdown menu.
And this is the backbone related code that will send the staff name along with other details to the server.
- save: function() {
-
- if ($.trim((this.$('#name').val()))==='')
- {alert('No name is inserted')}
- else
- {
- this.model.set({'name': this.$('#name').val(),'origin':this.$('#origin').val(),'staff':this.$(str)});//here is the staff detail
- if (this.model.isNew()) {
- this.collection.create(this.model, {success: this.close});
-
- } else {
- this.model.save({}, {success: this.close});
- }
- }
-
- },
And here is the jquery code that serves to "grab" what the user selected from the dropdown menu:
- $( "#staff" ).change(function() {//$staff is just the div where the dropdown is included
- var str = "";
-
- $( "#staff option:selected" ).each(function()
- {str += $( this ).text() + " "; });
- });
The var str is suppose to hold what staff the user selected.The above code is inserted at the end of the file but inside the function that encloses all of the backbone code.
The problem is that when I am about to send the data to the server(by pressing OK to a dialog box) I get I message in Crome Dev Tools saying that
str is not defined.
What am I doing wrong here?
Here is the whole code...at line 135 you will find the jquery code:
file
Some words are in Greek...do not be confused.