id of sqlform submit button in web2py

1k views Asked by At

I want to add a java-script to click a button when bottom of page is reached...the code for that is

<script>
function getScrollXY() {
    var scrOfX = 0, scrOfY = 0;
    if( typeof( window.pageYOffset ) == 'number' ) {
        //Netscape compliant
        scrOfY = window.pageYOffset;
        scrOfX = window.pageXOffset;
    } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
        //DOM compliant
        scrOfY = document.body.scrollTop;
        scrOfX = document.body.scrollLeft;
    } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
        //IE6 standards compliant mode
        scrOfY = document.documentElement.scrollTop;
        scrOfX = document.documentElement.scrollLeft;
    }
    return [ scrOfX, scrOfY ];
}

//taken from http://james.padolsey.com/javascript/get-document-height-cross-browser/
function getDocHeight() {
    var D = document;
    return Math.max(
        D.body.scrollHeight, D.documentElement.scrollHeight,
        D.body.offsetHeight, D.documentElement.offsetHeight,
        D.body.clientHeight, D.documentElement.clientHeight
    );
}

document.addEventListener("scroll", function (event) {
    if (getDocHeight() == getScrollXY()[1] + window.innerHeight) {
    document.getElementById('next').click()
     }
});
</script>

the problem is that the button is SQLFORM's submit button, so my question is what is the id of SQLFORM submit button, or how can i define it..i have tried the following but with no success.

form2.custom.widget.submit_button['_id']='next'

it shows the error 'NoneType' object does not support item assignment. there is a some excellent information on Custom CSS classes for SQLFORM widget input in web2py, but i still cant figure this out....

1

There are 1 answers

0
Anthony On BEST ANSWER

You can identify the submit button with a jQuery selector, such as "input[type=submit]" (or more specifically, "#submit_record__row input[type=submit]"). If you want to assign an ID, you can do:

form2.custom.submit['_id'] = 'next'

or:

form2.element('input[type=submit]')['_id'] = 'next'