Showing posts with label jQuery. Show all posts
Showing posts with label jQuery. Show all posts

Monday, July 20, 2015

jQuery datepicker() Uncaught TypeError: undefined is not a function


Can anyone please help me I am struggling with this problem for the past few day. Actually I included all the necessary plugins' but still the
$('#datepicker').datepicker() function is not defined ERROR.
I included the same plugins' in the other jsp of my projects there the datepicker works perfectly.
This is what I tried.
<script src="http://code.jquery.com/jquery-1.10.2.js"></script>
<script src="http://code.jquery.com/ui/1.10.4/jquery-ui.js"></script>
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css">

$( '#datepicker' ).datepicker();
solved :
Please double check the js files you include if you include the same js file twice are different version of same file twice, It will conflict. Have patient to go through to entire jsp or html file to check the js files.
also do this :
jQuery(document).ready(function(){
    $('#Yourdatepicker').datepicker();

});

Saturday, November 1, 2014

Checkbox does not change its checked value after postback

 have a checkbox from where I get the checked value but the first time works great but then I doesn't change at all after postback and always returns true.
I'm just doing this

bool accepted = this.chkAccepted.Checked;
My checkbox is inside a control. Not repeater not directly in a page.
<asp:CheckBox ID="chkAccepted" runat="server" Checked="true"/>Accepted

The first time it starts checked = true. I click my button first postback and work fine, then I uncheck, click my button but the checked is still true.
The first time it starts checked = true. I uncheck the checkbox and I click my button first postback and work fine, then I check, click my button but the checked is true, then I uncheck again and is always checked = true.
So, what is the bug for this?
I have another checkbox in the same control which has no Checked property initialized and always works fine. So how can I solve this problem please?



I realized that it's a .NET bug after some research. So when the property Checked of the checkbox is set to true in the aspx, this causes the problem. So, I removed this property and in the Page_Load event(server side) I initialized the checkboxes as true inside a Page.IsPostBack == false. And that's solved my problem.


solved

<asp:CheckBox ID="chkRem"  value="true" runat="server" Text="تذكرني"  />
  <asp:HiddenField ID="chkremHid" runat="server" />


<script>
   //check box for login
            $('#chkRem').change(function () {
                if ($('#chkRem').prop('checked'))
                    $('#chkremHid').val("True");
                else
                    $('#chkremHid').val("False");
            });

</script>



in code behind
use the hidden field value instead chekbox
c#
string check = chkremHid.Value;



Friday, October 31, 2014

call a JQuery function from code behind in C#

I want to call this JQuery function from C# code behind

ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "myfunction", "myFunction(params...);", true);

Tuesday, August 26, 2014

arrange the numbers in input name element array after remove one of it by js

I want after add a input and remove it, arrange the numbers in input name element array by jQuery but don't work for me after remove input. How can fix it?

Answer


I guess that you want to re-number the inputs after a remove, so that the array is made of contiguous numbers.
I have rewritten some things, among which the renumbering function, using an index contextual to the parent function.
function removeidx(context, clss, type) {
    var remove = $(context).closest(clss);
    remove.fadeOut('slow', function () {
        $(this).remove();
        var idx = 0;
        $(clss).each(function () {
            var checkBoxes = $('input[type="' + type + '"]', this);
            checkBoxes.each(function () {
                var name = $(this).attr('name');
                name = name.replace(/\d+/, idx);
                $(this).attr('name', name);
                idx = idx + 1;
            });
        });
    });
}

$(document).on('click change', 'a.adding', function (e) {
    e.preventDefault();
    var idx = $('.Row').length;
    $('.ffdd').append('<div class="Row"> <input name="arr[' + idx + '][]" type="text" value=""> <a href="#" class="remove_row" title="remove this row">Remove</a></div>');
});

$('.ffdd').on('click', 'a', function (e) {
    removeidx(this, '.Row', 'text');
})
You can see a working version there : http://jsfiddle.net/8sVWp/

ref 
http://stackoverflow.com/questions/14600150/arrange-the-numbers-in-input-name-element-array-after-remove-one-of-it-by-js

Monday, August 11, 2014

Make a div disappear or appear after few seconds with jQuery

You must have seen this effect when a particular element is visible for few seconds and then it fades out. Such things are used for notifications. You can also implement the same in your web application with jQuery. It is really very simple.

Find below jQuery code to show the div for 3 seconds and after that it fades out automatically. Use setTimeout() function to achieve this.

ref :http://www.jquerybyexample.net/2012/12/make-div-disappear-or-appear-after-few-seconds-jquery.html

Also Read:

$(document).ready(function() {
2    setTimeout(function() {
3        $(".content").fadeOut(1500);
4    },3000);
5});



 

Wednesday, July 9, 2014

jQuery('selector').on is not a function

I'm using jQuery 1.7.2 and live("click",function(){}) works but not on("click",fucntion(){}) i get jQuery("whatever").on is not a function.

I'm sure the 1.7.2 is loading.



Solution:

If you load 1.7.2 and then load an older jQuery version, you would get that error.


ref:
http://forum.jquery.com/topic/jquery-selector-on-is-not-a-function

MS in Computer Science with paid training in USA company