Click here to Skip to main content
13,900,411 members
Rate this:
 
Please Sign up or sign in to vote.
See more:
I am going nowhere with this since last three days.

I have a website with Right column and left column and center area. On the Right column I have Student searches with different criteria.
I have button "LoadSearch" that loads my user controls on Right column.
All the scripts related to Right column are placed StudenSearches.js file.
My document.ready is as follows, which loads my searches and loads my select options based on other selections. However this works only once ... the first time page is refreshed this works amazing. When first clicked on Load search button, it loads all my select options. When clicked on second time it doesn't load the select options.


$(document).ready(function (){

    $(":input", GetSubjectSearch()).bind("keydown", function () {  setTimeout(function() { SubjectChange(this); }, 4); })
	.bind("change", function() { setTimeout(function() { SubjectChange(this); }, 4); });

  
    
    $(":input", GetwildSearch()).bind("keydown", function() { setTimeout(function() { wildSearchChange(this); }, 4); })
	.bind("change", function() { setTimeout(function() { wildSearchChange(this); }, 4); })
	.bind("paste", function() { setTimeout(function() { wildSearchChange(this); }, 4); });

    
    GetYear().bind("change", function() { YearChange(this); });
    GetDepartment().bind("change", function() { DepartmentChange(this); });
    GetBranch().bind("change", function() { BranchChange(this); });
    GetClass().bind("change", function() { ClassChange(this); });
    GetSection().bind("change", function() { SectionChange(this); });

   
    $("#btnNew").button().click(ShowNewcontents);
	});



Those functions in document.ready area stuff that initializes my select options. So Forexample
Year Deapartment
      Branch class



are four select options that gets loaded when document.ready is executed. Now on a button click event, I have to reload everything in document.ready. So I created a function and called that on click event of button. However it doesn't load my select options when I click button for second time because page is not being refreshed on that click

What I have tried:

I have tried windows.load, widnows.addeventlistener and what not. But nothing seems to be working on second time without page being refreshed.

I really appreciate if someone can help me in this
Posted
Updated 30-Jun-16 5:31am
v4
Comments
Karthik_Mahalingam 30-Jun-16 12:05pm
   
asp.net ?
are you using update panel ?
sudevsu 30-Jun-16 13:41pm
   
No karthik. It is not update panel. My only concern is I bind "change" events on each of these select option on document.ready() so as soon as page is loaded it works great. Once I do something else on the page(not refresh) and then click on button again all the bind "Change" events are not executed if I try to make them as separate function and call also it didn't help
Karthik_Mahalingam 30-Jun-16 13:51pm
   
Document.ready will be loaded only once for a page cycle load.
And you cannot call this function explicitly
sudevsu 30-Jun-16 14:04pm
   
I am aware of that. So I placed all the functions and events from document.ready to a separate function sample(){//Placed all the code here}
And I am calling this SAmple function on document.ready and also later but that didn't help my bind events to work and eventually my selects options are not loaded
Karthik_Mahalingam 30-Jun-16 14:05pm
   
Can you post all the relevant code

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

This is the perfectly correct behavior. You handle $(document).ready which should really execute only once, only when you load/reload a page. What else would you expect?

You don't handle any "click" events at all, except one case with empty body of a click handler function at the end. If you need some processing on click, you have to handle "click" event. You show incomplete code though; I don't know what else you have written. It doesn't matter: if some event is not invoked, it means it is not handled (or, say, your observations are incorrect).

—SA
   
Comments
sudevsu 30-Jun-16 11:32am
   
I have click event that does what ever document.ready has like loading all my select options but it only works once because page is not being refreshed so it doesn't load my select options again when clicked

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Cookies | Terms of Service
Web03 | 2.8.190306.1 | Last Updated 30 Jun 2016
Copyright © CodeProject, 1999-2019
All Rights Reserved.
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100