Mathieu
Mathieu

Reputation: 4520

jQuery won't get called from MVC view

I use a jQuery DateTimePicker in many places in my web app. It works fine everywhere exept in one place where the calendar just won't pop up. Here's the source code of the page (view in Chrome).

<script>
    $('#example9').datetimepicker({ timeFormat: 'h:mm', stepMinute: 5, dateFormat: 'yy-mm-dd'
</script>

<div>
    <input type="text" name="example9" id="example9" value="2012-10-16 15:00" />
</div>

As you can see, I've reduced the code to the simplest and added an event listener. Nothing is triggered and nothing happens whenever I click the input.

Any clue?

Upvotes: 0

Views: 109

Answers (3)

Gabriele Petrioli
Gabriele Petrioli

Reputation: 195962

Make sure

  1. jQuery and your plugin are loaded.
  2. your script is run after the DOM is loaded (or at least after the used element is rendered). So move your script code after the div element, or use $(document).ready(function(){/*your-code*/});
  3. the id is unique in the html or it will fail.

Upvotes: 1

krillgar
krillgar

Reputation: 12805

Why would you do it that way? Instead of calling the datepicker on each specific input based on ID, just create an HTML class that all datepicker inputs will have. Then in your _Layout, or other JavaScript file that always gets called, turn everything with that class into a DatePicker.

Upvotes: 1

Sushanth --
Sushanth --

Reputation: 55740

You are doing this

.data("events")

I do not see a data-events attribute for the textbox

Upvotes: 0

Related Questions