简体   繁体   中英

Submit button works only as link to anchor

I have the following code:

<form enctype="multipart/form-data" id="search_form" name="search_form" action="thisfile.php#anchorname" method="get">

<!-- Lots of search fields here -->

<input name="search" type="submit" value="Search" />
</form>

<?php if (isset($_GET['search'])) {
// Search in database
?>
<div id="anchorname">
<!-- Table with results here -->
</div>
<?php
}

This works fine in IE (crazy, I know) but in Chrome and Firefox, after the form is submitted and the results table is displayed, the button doesn't resubmit the form but only makes the page scroll down to anchorname. In Chrome I can reload the page by clicking on the address bar and hitting enter, but when I do that in Firefox, nothing happens at all. What am I doing wrong?

In case this is useful to anyone, here's what I did, using JQuery:

$(function() {
    // ...
    <?php if (isset($_GET['search'])) { ?>
        var target = $("#anchorname");
        $('html,body').animate({
            scrollTop: target.offset().top
        }, 500);
    <?php } ?>
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM