Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript After .load() function in JQ – Javascript not working

  • This topic is empty.
Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #32265
    fjorko
    Member

    Hey Guys/Girls

    Done a search and could not find an answer to this question : Help as always much appreciated.

    I have a PHP doc and I’m trying to load the contents of this into a content div on one of my main pages like so :

    ("#divid_i_want_phpdoc_to_load_in").load("myphpfile.php");

    Now the content of the PHP file is just a simple form that will be posted to itself for validation.

    The problem I have is that when I do this – everything loads perfectly, but all of a sudden, my javascript code does not work anymore ?

    If I add the “javascript” tags in the PHP file that gets loaded stuff starts working. It’s as if the elements of the form that is loaded as part of the php file is “orphaned”” from the main page into which it is loaded, almost as if it doesn’t recognize the script tags in the “header” section of the main page.

    Hope I make sense .

    Anyone seen this ?

    I was wondering if it isn’t because the main page’s head section is loaded as a PHP include ( header.php )…. but surely that shouldn’t matter ?

    Thanks again for any help offered.

    #51892
    fjorko
    Member

    I think I know why …..

    The content is loaded without the page being refreshed, so $(“document”).ready() isn’t fired on the loaded content in the div so it is unaware of the javascript which loads in the head tags if a page initializes ? Am I right ?

    If I am – does this mean that it is not a good idea to load a form using the JQ load() function into an element of another page ( Ajaxing )?

    #51883
    jamygolden
    Member

    @fjorko that is correct =)
    Have a look at delegate()

    #51884
    fjorko
    Member

    jamie – how is that going to solve my issue.

    PS. I found that by doing a $.getScript(“mycustomscript”); seems to work, but it dosn’t seem to be the most elegant way of doing it. It also confirms that my problem lies in the fact that the dom is not refreshed by the load() function and therefore my custom script is not read in the head tags hence why my buttons and things do not fire…..

    #51826
    jamygolden
    Member
    #51795
    stefanbar
    Member

    Hi fjorko

    Not sure if you have sorted this issue out by now, i usually use the $.get() method to load php files into my website. Otherwise post the code so that we can have a look at it.

    #51730
    fjorko
    Member

    jamie – i read that post, and it is exactly my issue. i also use load() to load a php page that consists of basically a registration form only. once the load finishes ( works 100% ) , then as the OP said – javascript does not work anymore.

    Now I hear about live() and delegate() , but have no clue how to implement it , so for now i run a $getScript() to load my custom .js so my javascript at least works.

    On a side note: I’m now hitting a brick wall with form validation that gets posted to a php file, checked and any errors sent back in json object format to the form – i kinda got it working, but …aaagghhhhhhhh……something just isn’t right….

    I get this :

    ” Warning: in_array() [function.in-array]: Wrong datatype for second argument ….”

    ( not even google has any more answers for me LOL )

    I kinda worked it out that the array is not an array, but it’s only NOT an array if one of the fields i send is NOT in the DB…

    so frustrating…wish i had someone next to me to help me out with this……

    anyone care to remote assist ? LOL !!! kidding

    I’m absolutely determined to get it right – I’m learning SO much as I go ! I’m hooked on this – absolutely love it !!!!

    this is the form I’m trying to make work !

    http://test.epbudgerigars.com/members.php ( register bit )

    I’m not even sure If i’m doing it right !, but it’s so much fun to struggle like this and BAM! finally get it working !

    *sigh* :-)

    Cheers !

Viewing 7 posts - 1 through 7 (of 7 total)
  • The forum ‘JavaScript’ is closed to new topics and replies.