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 5 of 5
  1. #1
    Senior Coder
    Join Date
    May 2004
    Posts
    1,441
    Thanks
    15
    Thanked 0 Times in 0 Posts

    can you spot my mistake

    this must be simple but i'm not spotting my error - the ajax is loading the value but not showing it in my div

    javascript is


    function Loadtel(strtel,telo) {
    //alert("here");

    urltoajax = "gettel.asp?1=1"

    urltoajax = urltoajax + '&id_job=' + strtel
    urltoajax = urltoajax + '&rnd=' + Math.round(Math.random() * 10000)
    alert(urltoajax);
    $.ajax({
    url: urltoajax,
    cache: false,
    success: function(html) {
    $(telo).html(html);
    }
    });

    }



    html



    <a href="javascript:void(0)" onClick="return Loadtel(12446,'tel12446');" class="visittext4red">show </a>
    <div id="tel12446"></div>

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,020
    Thanks
    75
    Thanked 4,323 Times in 4,289 Posts
    $(telo).html(html); is wrong.

    Because you are calling with telo equal to "tel12446", right?

    So you need the "#" in front of that to make it a valid jQuery selector. Try
    $("#" + telo).html(html);

    And when calling the function, you'd be better off doing
    Code:
          
        ... onclick="return Loadtel(12446,this.id);" ...
    though that's not very important.

    Finally, href="javascript:..." is obsolete. Just use href="#". So long as your function returns false (which it is *NOT* doing now!), that will work great.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #3
    Senior Coder
    Join Date
    May 2004
    Posts
    1,441
    Thanks
    15
    Thanked 0 Times in 0 Posts
    thanks! you got it

  • #4
    Senior Coder
    Join Date
    May 2004
    Posts
    1,441
    Thanks
    15
    Thanked 0 Times in 0 Posts
    the reason i am not using href="#". is because it jumps to the top of the page

  • #5
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    10,966
    Thanks
    0
    Thanked 236 Times in 233 Posts
    Add return false at the end of the function as Old Pedant mentioned.


  •  

    Posting Permissions

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