SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Addict Feudalism's Avatar
    Join Date
    Jun 2002
    Location
    Buenos Aires, Argentina
    Posts
    361
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    when I call to a function, it anchors at the top

    Using this <a>, i call the function below.

    Code HTML4Strict:
    <a href="#" class="Estilo2" onClick="agregar_row('<?=$tabla[nombre];?>');">

    ... agregar_row.

    Code JavaScript:
    function agregar_row(tabla){
        for (i=0; i<10; i++){
            row="row/agregar/" + tabla + "/" + i;
            reset_status = "status/agregar/" + tabla + "/" + i;
            if (document.getElementById(row).style.display=='none'){
                document.getElementById(row).style.display='';
                document.getElementById(reset_status).value='S';
                i=11;
            }
     
        }
    }

    This function is working fine, but each time I call it it makes the browser to point at the top of the page, just if it were calling an anchor to the top. How can I use the function but evade that "repositioning" of the browser?

    In IE, FF, Crome, they are the same.

  2. #2
    SitePoint Guru whisher's Avatar
    Join Date
    May 2006
    Location
    Kakiland
    Posts
    732
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,
    you should do a thing like

    Code JavaScript:
    onClick="agregar_row('<?=$tabla[nombre];?>'); return false;"

    Bye.

  3. #3
    SitePoint Member
    Join Date
    Apr 2010
    Posts
    21
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    To expand on whisher's (correct) response a bit, returning false in the onclick statement will stop the browsers from performing their default action for when an anchor element is clicked. This will stop the URL in the address bar from changing to www.whatever.com/#, and should stop the browser from moving to the top of the page.


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
  •