开发者

Target 'Search' in Whole Page

I want my search bar to complete a search, however, I want the target to be 'wholepage' and not to totally move to another page?

<div id="search_开发者_JS百科anything"> 
    <form action="/search.php" method="get" id='searchForm'> 
        <div class="searchFormDiv"> 
            <input type="text" name="search" value="Search Mail..." id="search" onfocus="if( $(this).attr('value').indexOf('...') >= 0) $(this).attr('value',''); $(this).select();" /> 
        </div> 
    </form> 
</div>


<form action="<?php echo $_SERVER['REQUEST_URI']; ?>" method="get" id='searchForm'> 

Don't forget that most of the time you need to process the form on the same page too (or include a separate form processor script on that page).

For example if you want to process the form with another PHP file, you can paste this anywhere above the form:

<?php if(isset($_GET['search'])) include 'formprocessor.php'; ?>


When I enter that code I get the following link: - liveternet.com/?search=(My search), however, I want: liveternet.com/search.php?search=(My Search) << including the search being complete in the same webpage :) (and not redirected to another)


Use jQuery:

$('form').submit(function() {
    $.post(
    'do_query.php',         // File with query
    { num: '1', str: 'string' },    // Vars passed as post
    function(responseText){     // Callback
        $('#your_div').html(responseText); // Load content results from do_query page.
    },
    "html"              // Set type as html
);
    preventDefault();           // Prevent form from submiting
});

This should work. Please give feedback.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜