I have radio button with values: "By title" and "By actor". If user select By title the textbox auto-complete shows list of movies contain the word user type in the textbox, and if user select "By actor" the same textbox will show list of actors. Also, in case of "by title" there is a button "search movies by this title" which will open a new window showing list of movies contain the word that user inserted in the textbox. (The same button will be shown in case of "by actor", which shows list of movies by that actor)
Problem:
If user select "by actor", and write an actor name in the textbox like "Tom Cruise", and then click the button "movies by this actor", a new window ("movielist.php") is opened showing list of movies by "Tom cruise". Now if then user change the radio button and select "by title" and write a title name like "Frozen" and click the button "movies by this title", the new window is opened but it shows list of movies by "Tom cruise" instead of list of movies contain word "Frozen".
This image may show my problem more clearly:
This is the code:
<div id="m_scents" class="field">
<label style="margin-bottom:10px;" for="m_scnts"></label>
<p>
<input class="autofill4" type="textbox" name= "q27[]" id="q" placeholder="Enter movie, actor or director name here" />
<input type="button" value="Search" id="btnSearch" />
</p>
</div>
$(document).ready(function () {
$("input[id='selectType']").change(function(){
$("#q").val('');
if ($(this).val() == "byTitle") {
$("#m_scents").show();
$("#q").focus();
$("#q").autocomplete({
minLength: 0,
delay:5,
source: "filmsauto.php",
focus: function( event, ui ){
event.preventDefault();
return false;
},
select: function( event, ui ) {
window.selected = ui.item.value;
}
});
} else
if ($(this).val() == "byActor"){
$("#m_scents").show();
$("#q").focus();
$("#q").autocomplete({
source: "actorsauto.php",
minLength: 2,
focus: function( event, ui ){
event.preventDefault();
return false;
},
select: function (event, ui){
window.selectedVal = ui.item.value;
}
});
}
$('#btnSearch').on('click', function (e) {
window.textbox = $('#q').val();
popupCenter("movielist.php","_blank","400","400");
});
this is movielist.php:
<div id= "field"
</div>
<script type="text/javascript">
var textbox = parent.window.opener.textbox;
$.ajax({
url: 'childfilm.php',
datatype: "json",
//I FEEL THE PROBLEM IS IN THE LINE BELOW WHERE ALL 3 VALUES ARE PASSED IN CASE OF CLICKING ANY BUTTON..
data:{p:textbox},
success: function(response) {
$("#field").html(response);
}
});
</script>*
and here is childfilm.php:
<?php
if(isset($_GET['q']) && !empty($_GET['q'])){ //IN CASE OF BY ACTOR
try{
include('imdbConnection.php');
$sql = $conn->prepare("SELECT DISTINCT movieName FROM cast_movie WHERE castName = :q");
$sql->execute(array(':q' => $_GET['q']));
while($rows = $sql->fetch(PDO::FETCH_ASSOC)){
$option = '<a href=movie.php?title="' . $rows['movieName'] . '">' . $rows['movieName'] . '</a><br />';
$html .= $option;
}
} catch(PDOException $e){
echo 'ERROR: ' . $e->getMessage();
}
echo $html;
exit;
}
?>
<html>
<head>
<meta http-equiv="content-Type" content="text/html" charset=UTF8" />
<link type="text/css" rel="stylesheet" href="filmstyle.css" media="screen" />
</head>
<body>
<div class= "movielist">
<table id= "films">
<tr>
<th></th>
<th>year</th>
<th>Title</th>
</tr>
<?php
if (isset($_GET['p']) && !empty($_GET['p'])) { // IN CASE OF BY TITLE
include('imdbConnection.php');
$query = $conn->prepare("SELECT DISTINCT movieName, year, posterLink FROM film_info WHERE movieName LIKE :p");
$query->execute(array(':p' => '%' . $_GET['p'] . '%'));
if ($query->rowCount()) {
while ($row = $query->fetch(PDO::FETCH_ASSOC)):
?>
<tr>
<td><img class='imdbImage' id="image" src='imdbImage.php?url=<?php echo $row['posterLink']; ?>' alt="" /></td>
<td><label id='year'><?php echo $row['year']; ?> </label></td>
<td><a href="movie.php?title=<?php echo urlencode($row['movieName']); ?>"><?php echo $row['movieName']; ?></a></td>
</tr>
<?php
endwhile;
} else {
echo '<td colspan="3">Sorry, there are no film matching your search</td>';
}
}
?>
</table>
</div>
</body>
</html>