SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Hybrid View

  1. #1
    SitePoint Addict
    Join Date
    Dec 2005
    Posts
    381
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Replace content inside div instead of show/hide

    Can anyone tell me how I can change the code below so that instead of all the fade in fade out stuff the function will actually replace whatever is inside a div called Myholder with the response this script pulls in?

    Here's the code I need to change.

    Code JavaScript:
    <script type="text/javascript">
    $(document).ready(function() {
    $('#wait_1').hide();
    $('#drop_1').change(function(){
    $('#wait_1').show();
    $('#result_1').hide();
    $.get("func.php", {
    func: "drop_1",
    drop_var: $('#drop_1').val()
    }, function(response){
    $('#result_1').fadeOut();
    setTimeout("finishAjax('result_1', '"+escape(response)+"')", 400);
    });
    return false;
    });
    });
     
    function finishAjax(id, response) {
    $('#wait_1').hide();
    $('#'+id).html(unescape(response));
    $('#'+id).fadeIn();
    }
    </script>

    drop_1 is the name of a drop down which when changed runs this script which brings back a second dropdown with data relating to the first one.

    If I need to post more info to get some help with this please let me know.

    Thanks in advance.

  2. #2
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,705
    Mentioned
    102 Post(s)
    Tagged
    4 Thread(s)
    Currently it is a div called result1 that is affected:

    Code:
    $('#result_1').fadeOut();
    setTimeout("finishAjax('result_1', '"+escape(response)+"')", 400);
    If you don't want the fadeout/fadein parts occurring, you can remove them so that you just have:

    Code:
    }, function(response){
        setTimeout("finishAjax('myHolder', '"+escape(response)+"')", 400);
    });
    ...
    function finishAjax(id, response) {
        $('#wait_1').hide();
        $('#'+id).html(unescape(response));
    }
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  3. #3
    SitePoint Addict
    Join Date
    Dec 2005
    Posts
    381
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks for the help, works perfectly now.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •