Two jQuery/JavaScript functions not being called -


I have a working MVC application that lists two catalog boxes and buttons for different things in the listbase. Execute jQuery functions correctly, except the levups and movements which are never called (set breakpoints). F12 console is clean and there are no JavaScript errors. I have two buttons in question:

  & lt; Button type = "button" id = "upclick =" moveUp () "& gt; above & lt; / button & gt; button type =" button "id =" bottom "onclick =" hootdown () "& Gt; Below & lt; / button & gt;  

Below is the jQuery code. Should the layout and movements function be within the "global" function?

 < Code> & lt; script src = "~ / scripts / jquery-2.1.1.js" & gt; & lt; / script> gt; & lt; script & gt; each (function () {$ (this). Click on the value of $ ("function") ($ {"(" function ") ($ {" ("# add") (function () {$ ("# listBoxAvail"> $ (This) .val ( ); Temp = $ (this); temp.val ('L' + val) $ (temp) .appendTo ("# listBoxSel");});}); $ ("# rem Ove "") .click (function () {$ ("# listBoxSel> gt; option: selected"). Each (function () {$ (this) .remove (). AppendTo ("# listBoxAvail");}) }} $ ("# Remove-all") ("click", function (event) {$ ('# listBoxSel Options') .prop ('selected', true); $ ("# delete"). $ ("Selected", true) $ ("click");}); $ ("# select-all") ("click", function (event) {$ ('# listBoxAvail option' #add "). Trigger ("click");});}); Function Movedown () {var Selected Optic = $ ('# List Box Seal & gt; Option [Selected]'); Var nextOption = $ ('# lstBoxSel' option [selected] '). Next ("Options"); If ($ (next option) .text ()! = "") {$ (Selected option) .remove (); $ (NextOption) .after ($ (selectedOption)); }} Function MoveUp () {var selectedOption = $ ('# lstBoxSel & gt; Option [Selected]'); Var prevOption = $ ('# lstBoxSel' option [selected] ') Prev ("Options"); If ($ (Procopation) .text ()! = "") {$ (Selected Option) .remove (); $ (PrevOption) before ($ (selectedOption)); }  

You are saying that "never move MoveUp and MoveDown It is called ", but " the console is clean and there are no JavaScript errors. " This means that the function is being called, otherwise, you will not see an error one function unchanged .

So, with that information, we can guess that the error is in your work. When you use jQuery, when the jQuery object is empty, it will silently (no error) will fail.

I do not have access to your HTML, so I'm guessing here, but you select an element and use this selector option [selected] . You're probably trying to get the selected element but it does not do what you want select it option which is selected Is the specialty. Your HTML probably is not.

: Selected : This will get the selected option Use:

  Function Movedown () {var selectedOption = $ ('# ListBoxSel' option: selected '); Var nextOption = selectedOption.next ("Options"); If ($ (next option) .text ()! = "") {$ (Selected option) .remove (); $ (NextOption) .after ($ (selectedOption)); }}  

Comments

Popular posts from this blog

java - Can't add JTree to JPanel of a JInternalFrame -

javascript - data.match(var) not working it seems -

javascript - How can I pause a jQuery .each() loop, while waiting for user input? -