Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Jun 2011
    Posts
    12
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Question Replace content 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.

    <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
    Senior Coder
    Join Date
    Apr 2011
    Location
    London, England
    Posts
    2,120
    Thanks
    15
    Thanked 354 Times in 353 Posts
    Assuming 'Myholder' is the id for the div
    Code:
    function finishAjax(id, response) {
    
    $('#Myholder').html(unescape(response));
    
    }
    You could strip out other stuff you don't need (including the id parameter).
    "I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
    Validate your HTML and CSS

  • Users who have thanked AndrewGSW for this post:

    sketchgal (06-12-2011)

  • #3
    New Coder
    Join Date
    Jun 2011
    Posts
    12
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Thanks so much for the help with that it works perfectly now. Don't suppose you could help me with a checkbox issue I'm having aswel could you?


  •  

    Posting Permissions

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