Search code examples
phpjavascriptonclickbuttonclicksearch-form

Search form doesn't work "onclick"


Im having trouble with a search box. It only works when i hit "Enter", and not when i click the "search" button..

Here are the codes:

(php)

<form id="search" action="search.php" method="GET">
                                <input type="text" name="s">  
    <a class="submit" onClick="document.getElementById('form').submit()"></a>

(js)

$(function(){
var s=location.search.replace(/^\?.*s=([^&]+)/,'$1')
    ,form=$('#search')
    ,form=$('#search-form')
    ,input=$('input[type=text]',form)
    ,results=$('#search-results').height(0)
    ,src='search/results.php'
    ,ifr=$('<iframe width="100%" height="100%" frameborder="0" marginheight="0" marginwidth="0" allowTransparency="true"></iframe>')

if(results.length)      
    ifr     
        .attr({
            src:src+'?s='+s
        })
        .appendTo(results)
    ,input
        .val(decodeURI(s))

window._resize=function(h){     
    results
        .height(h)
}

})

Thanks in advance for any help! ;)


Solution

  • I think document.getElementById('form') should be:

    document.getElementById('search')

    That's what immediately pops out at me.