sdnr1
sdnr1

Reputation: 307

Javascript autoclick not working

I am using a script to make tables in html sortable. The script is here- http://www.kryogenix.org/code/browser/sorttable/. I want the text which sorts the html table to be clicked automatically when the i loaded. The autoclick script i am using is this-

<head>
<script LANGUAGE='javascript'>
function autoClick(){
document.getElementById('sort').click();
}
</script>
</head>
<body onload="autoClick();">
<table><tr><th><p id="sort">Click here to sort the table</p></th>...

The problem is that this is not working and i am confused that why this isnt working.

--------------------EDIT------------------

Sorry for this but actually i was typing something wrong in the body onload statement. Thus the script i was using was correct.

Upvotes: 1

Views: 2037

Answers (3)

ke20
ke20

Reputation: 665

Where have you defined your event?
Because I see juste one function in your onload.

Below, a little example which work fine:

<html>
    <head>
        <script type='text/javascript'>
        var init = function() 
        {
            document.getElementById('test').addEventListener('click', function() {
                alert('Auto test is ok');
            }, false);
        };

        function autoClick(){
            document.getElementById('test').click();
        }

        </script>
    </head>
    <body onload="init(); autoClick();">
        <button id="test">Test</button>
    </body>
</html>

Upvotes: 1

somasundaram
somasundaram

Reputation: 139

I think you missed the class name in the table

Please add your table tag with class name called "sortable".

Upvotes: 0

Dave Homer
Dave Homer

Reputation: 168

It's always safer to use Jquery library. Just include the latest Jquery library on your header section of the page:

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8/jquery.min.js" type="text/javascript"></script>

and this function Should solve your issue:

$("#sort").live('click');

Upvotes: 0

Related Questions