通过html按钮发布搜索值

时间:2012-03-25 13:23:51

标签: php html

我正在寻找用以下按钮替换低位输入文本字段的可能性:<input type="button" class="button" name="search" value="Urban" onclick="">

HTML CODE:

<form method="post" action="search.php" id="search_form">
    <input type="text" name="search" value="<?php echo $_POST['search']; ?>" class="search_sounds"/>
    <input type="submit" value="" class="submit" /> 
</form> 

整个脚本应该搜索数据库的声音:

PHP代码:

<?php if(isset($_POST['search']) && !empty($_POST['search']))
    {
        include('searchfunction.php');

        if(count($data) > 0)
        {
?>
                    <script type="text/javascript"> 
                    $(document).ready(function(){

                    var description = ''; 
                    var myPlaylist = [ 
<?php
                        echo(implode(',', $data));
?>
             ]; 

                    $('#main').ttwMusicPlayer(myPlaylist, { 
                    autoPlay:false, 
                    description:description, }
                    );

                    }); 
                    </script>
<?php
        }
        else
        {
            echo ('No sounds found.');
        }
    }
?>

1 个答案:

答案 0 :(得分:0)

在按钮中添加id元素,就像这样(我删除了onclick =“”代码)

<input type="button" class="button" name="search" value="Urban" id="search_button">

然后使用一些简单的jQuery:

$('#search_button').click(function() {
  $('#search_form').submit();
});