0

I have the follow code:

    $(document).ready(function() { 
    $(function detinator() {
                    $("select#arhpcnDetinator").jCombo("services/detinatori.php", { 
                            initial_text: "Detinator",
                            selected_value: $("input#arhpcndetinatorID").val()
                    });
});    
});

and everything is working perfect.

When I try to call same function on other event, it's stop working.

  $(document).ready(function() { 
    $(function detinator() {
                    $("select#arhpcnDetinator").jCombo("services/det.php", { 
                            initial_text: "Detinator",
                            selected_value: $("input#arhpcndetinatorID").val()
                    });
    $("#imag").click(detinator);
    });
});

HTML is:

<img src="Sync.png" id="imag" onclick="ziceva">

Please help me! Thank you in advance.

4 Answers 4

2

I would remove it from the double-wrapper you have there, like so:

$(document).ready(function() { 
    var detinator = function() {
      $("select#arhpcnDetinator").jCombo("services/det.php", { 
        initial_text: "Detinator",
        selected_value: $("input#arhpcndetinatorID").val()
      });
    };

    $("#imag").click(detinator);
});
Sign up to request clarification or add additional context in comments.

2 Comments

The "double wrap" was weird. I would move the function declaration out of the ready function.
This is not equivalent to his code unless you add a call to detinator. It's a very odd construct which will result in that function being called on ready. Though I doubt it's intentionally, his way would also add an additional click handler on each call.
0

Would you be able to try something like this?

$(document).ready(function() { 

   $("#imag").click(function() {
                $("select#arhpcnDetinator").jCombo("services/det.php", { 
                        initial_text: "Detinator",
                        selected_value: $("input#arhpcndetinatorID").val()
                });

   });


});

1 Comment

this is not what I want, because when DOM are loading, jCombo feed my select box. After I add a new record (on the other window) I must refresh/reload select list and recall jCombo(jSON).
0

Try converting the detinator function into javascript.

$(document).ready(function() { 
    function detinator() {
            $("select#arhpcnDetinator").jCombo("services/det.php", { 
                initial_text: "Detinator",
                selected_value: $("input#arhpcndetinatorID").val()
            });
    }
    $("#imag").click(detinator());
});

2 Comments

You should not be calling detinator. You are passing to click the return value of detinator which is nothing. Also, the original code executes the function on ready.
But I must to call detinator function :). When DOM are loading, jCombo feed my select list. After I add a new record (on the other window) I must refresh/reload select list and recall jCombo(jSON) with a click on #imag.
0

I think the open parenthesis { that you have after $("select#arhpcnDetinator").jCombo("services/det.php", is the problem. Remove it and try again..

1 Comment

That's not a parenthesis, it's a curly brace or bracket. And I see no issue with it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.