I used the following code to post a search value via an html button. But onlick seem to be not working. The value is posted whether I click the button or not. How can fix this problem??
<form method="post" action="urban.php" id="search_form">
<input type="button" class="button" name="search" value="Urban" onlick="<?php $_POST['search'] = 'Urban'; ?>">
</form>
<?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.');
}
}
?>
PHP & JS are not executed at the same time : PHP is executed server side, to create the HTML code. Javascript is executed on the client side, when all HTML is already rendered.
Here is a quick fix: