I've got some code that uses load to add some help info to a page when the
user clicks on a help button. 

I pass the current contents of the div to the php function that provides the
help info.  The php function checks the current contents, and if it sees
that the help info is already on the screen, it toggles it off, and puts the
help button back in its place.

I added a callback so that after the load, the page will scroll to the help
info just added.

All this works great, but the scroll only works the first time:

- The user clicks the help button, and the help text is loaded and appears,
and page scrolls to the help text - correctly.
- The user clicks a close box button,  and the help text disappears and is
replaced by the help button - correctly.
- The user clicks the help button for the second time, and the help text is
loaded and appears - but the page doesn't scroll to the help text. 

How can I correct this?

Thanks in advance to all for any info. 


///JAVASCRIPT/JQUERY
 function ScrollToDiv(theDivID)
 {
         $("html,body").animate({ scrollTop: $("#"+theDivID).offset().top });
 }
 
   $(document).ready(function(){
        
   $("#HelpInfo").click(function(){
             var htmlStr = $(this).html();

            
$("#HelpInfo").load("http://localhost:8888/index.php/your_plan/ShowHelpInfo";,
{contents: htmlStr}, ScrollToDiv("HelpInfo"));
    });


///PHP CODE - CodeIgniter framework - this function is callable as
///http://localhost:8888/index.php/your_plan/ShowHelpInfo

        function ShowHelpInfo()
        {
                $lengthOfCurrentContents = strlen($_POST['contents']);
                if ($lengthOfCurrentContents < 500)
                {
                        $output = "Help info and Close Box";

                        echo $output;
                }
                else 
                {
                        $output = "Help Button";

                        echo $output;
                }
                
        }
-- 
View this message in context: 
http://www.nabble.com/Newbie-Question%3A-Callback-for-Load-Only-Works-the-First-Time-Load-is-Called--tf4720377s27240.html#a13494683
Sent from the jQuery General Discussion mailing list archive at Nabble.com.

Reply via email to