Can someone explain me why this code below does not hit the on change function?
HTML
<div class="form-group">
#Html.DropDownList("Relatorios", ViewBag.Tipos as SelectList, new { id = "Relatorios"})
</div>
Script
$(document).ready(function () {
$("#Relatorios").on("change", function () {
alert("Success");
});
});
I expected that function to hit when I change de option in the drop down list
I resolved the problem with the code below
$(window).load(function () {
$("#Relatorios").on("change", function () {
settabledata();
});
Related
I need help with my UI element. I want to show next calendar when first close.
Unfortunately function onClose doesnt run :/ I don't know why..
$(function () {
$('#datepickerDate1').datepicker({
onClose: function () {
$("#datepickerDate2").datepicker("show");
}
});
});
Website online:
http://nauka.cf/issue/ui-elements/search-box-1/index.html
Thanks!
solve:
$(function () {
$('#datepickerDate1').datepicker().on('changeDate', function (ev) {
$('#datepickerDate1').datepicker('hide');
$('#datepickerDate2').datepicker('show');
});
});
Try following will solved your issue.
$("#datepickerDate2").focus();
I'm just learning jquery, and I'm running into behavior I don't understand. I have:
html:
<div id="tour" data-location="london">
<button>Get Photos</button>
<ul class="photos"></ul>
</div>
and
jquery:
var tour = {
init: function () {
$("#tour").on("click", "button", alert("clicked"));
}
};
$(document).ready(function () {
alert("hello");
tour.init();
});
The "hello" alert is appearing after the dom is loaded, as I would expect. However the "clicked" alert is firing as well, and does not subsequently fire when the button is pressed.
http://jsfiddle.net/abalter/295sgf5c/2/
If you want it to be executed when clicking on the button, you would need to wrap it in a function:
Updated Example
var tour = {
init: function () {
$("#tour").on("click", "button", function () {
alert("clicked")
});
}
};
See this fiddle.
Your callback needs to be a function, like this:
var tour = {
init: function () {
$("#tour").on("click", "button", function(e){alert("clicked")});
}
};
What am I doing wrong in my jQuery widget?
I have divs on page, and call in a document.ready function:
$(".codeline").comments();
Html containes:
<div class='codeline'> (some text) </div>
...
<div class='codeline'> (some text) </div>
And the widget:
jQuery.widget("rmc.comments", {
_create: function () {
this.element.on("click", function () { alert(1); }); // THIS DOESN'T WORK (event not fired)
//this.element.css("color", "red"); -- THIS WORKS
}
});
It does work. You are probably calling your widget before defining it. Change to:
$.widget("rmc.comments", {
_create: function () {
this.element.on("click", function () { alert(1); });
//this.element.css("color", "red");
}
});
$(".codeline").comments();
http://jsfiddle.net/10tdarhk/
i am developing an Asp.net application when i call javascript function from codebehind i found that for example:
click event not fired
i have a javascript function that fill the dropdown list with items using ajax but when page loaded i found dropdown list empty
i am using RegisterClientScriptBlock to execute the javascript code
so is there any solution for these problems?
code snippet:
code behind:
ClientScript.RegisterClientScriptBlock(this.GetType(), "ClientBlock", javacode.ToString());
this what in javacode variable :
<script type="text/javascript">
<!--
function ExecuteScript()
{
$("#divGender input").click();
GetDMspecifyList(5);
$("cp1_drpDMSpecify").removeAttr('disabled');
$("cp1_drpDMSpecify option:selected").val(4);
$("#divFamily input").click();
}
</script>
// -->
this the function used to fill dropdown list but it is not working
function GetDMspecifyList(DMID) {
$("#DMLoader").show();
$.getJSON('FillDropDownLists.aspx?DMTypeID=' + DMID, function (types) {
$.each(types, function () {
$("#cp1_drpDMSpecify").append($("<option></option>").val(this['DMTypeCode']).html(this['DMTypeName']));
});
$("#DMLoader").hide();
$("#DMSpecify_span").show();
$("#cp1_hdDMType").val($("#cp1_drpDMSpecify").val());
$("#cp1_drpDMSpecify").removeAttr('disabled');
});
}
First of all the function "ExecuteScript()" is lacking it's closing curly brace "}".
Also, is the ExecuteScript() function called anywhere?
EDIT
You could try something similar to the code below :
<script type="text/javascript">
<!--
function ExecuteScript() {
$("#divGender input").click();
GetDMspecifyList(5, function() {
$("cp1_drpDMSpecify").removeAttr('disabled');
$("cp1_drpDMSpecify option:selected").val(4);
$("#divFamily input").click();
});
}
function GetDMspecifyList(DMID, callback) {
$("#DMLoader").show();
$.getJSON('FillDropDownLists.aspx?DMTypeID=' + DMID, function (types) {
$.each(types, function () {
$("#cp1_drpDMSpecify").append($("<option></option>").val(this['DMTypeCode']).html(this['DMTypeName']));
});
$("#DMLoader").hide();
$("#DMSpecify_span").show();
$("#cp1_hdDMType").val($("#cp1_drpDMSpecify").val());
$("#cp1_drpDMSpecify").removeAttr('disabled');
callback();
});
}
$(function() { ExecuteScript(); });
// -->
</script>
i have implemented a java script to bounce an image on my asp.net mvc 3 web application, if i write the Jscript as follow it will work fine:-
$(document).ready(function () {
$("#to-get-bigger").mouseover(function () {
$(this).effect("bounce);
});
});
but if i write it this way it will not work !! ,, so what might be the reason behind this :-
$(function () {
$("to-get-bigger").mouseover(function () {
$(this).effect("bounce");
});
});
You are missing the hash # for your selector. I've fixed it:
$(function () {
$("#to-get-bigger").mouseover(function () {
$(this).effect("bounce");
});
});
You forgot the # in front of "to-get-bigger".
It's a typo.