2011-12-03 9 views
1

私のページにあるフォームからインスタント検索結果を表示しようとしていますが、クエリから何の結果も得られません。私が書いたコードは、フォームを正しく呼び出すことができないか、onblur/onfocusの値をフォームのjQueryの記述方法に変更すると、onblue/onfocusの値がデフォルトのテキストになるようになります。クエリに含まれていません。任意のアイデア?フォーム.keyup(function()jQuery即時検索

[HTML]

<script type="text/javascript" src="js/BookSearch.js"></script> 
<form action="php/DisplayBooks.php" method="POST" class="searchbooks"> 
<table width="620" border="0"> 
<tbody> 
<tr> 
<td width="114" align="right">By Course :</td> 
<td width="144"><input type="text" id="Subject" value="Subject..." onblur="if (this.value == ''){this.value = 'Subject...'; }" onfocus="if (this.value == 'Subject...') {this.value = ''; }" /></td> 
<td width="348"><input type="text" id="Course" value="Number..." onblur="if (this.value == ''){this.value = 'Number...'; }" onfocus="if (this.value == 'Number...') {this.value = ''; }" /></td> 
</tr> 
<tr> 
<td align="right">By Title :</td> 
<td><input type="text" id="Title" value="Book Title..." onblur="if (this.value == ''){this.value = 'Book Title...'; }" onfocus="if (this.value == 'Book Title...') {this.value = ''; }" /></td> 
<td><input type="text" id="Edition" value="Edition..." onblur="if (this.value == ''){this.value = 'Edition...'; }" onfocus="if (this.value == 'Edition...') {this.value = ''; }" /></td> 
</tr> 
<tr> 
<td align="right">By ISBN :</td> 
<td><input type="text" id="ISBN" value="ISBN..." onblur="if (this.value == ''){this.value = 'ISBN...'; }" onfocus="if (this.value == 'ISBN...') {this.value = ''; }" /></td> 
<td><input type="reset" class="sub-button" value="Reset" /></td> 
</tr> 
</tbody> 
</table> 
</form> 
<div id="BookSearch_results"></div> 

[jQueryの]

$(document).ready(function(){ 
$('.searchbooks').keyup(function() { 
    var subject_term = $('#Subject').val(); 
    var course_term = $('#Course').val(); 
    var title_term = $('#Title').val(); 
    var edition_term = $('#Edition').val(); 
    var isbn_term = $('#ISBN').val(); 
    $.post('php/Display.php', { subject_term: subject_term, course_term: course_term, title_term: title_term, edition_term: edition_term, isbn_term: isbn_term }, function(data) { 
    $('#BookSearch_results').html(data); 
    }); 
}); 
}); 

[PHP]

<?php 
if (isset($_POST['subject_term'], $_POST['course_term'], $_POST['title_term'], $_POST['edition_term'], $_POST['isbn_term'])){ 

require 'Connect.php'; 

$subject_term = mysql_real_escape_string(htmlentities($_POST['subject_term'])); 
$course_term = mysql_real_escape_string(htmlentities($_POST['course_term'])); 
$title_term = mysql_real_escape_string(htmlentities($_POST['title_term'])); 
$edition_term = mysql_real_escape_string(htmlentities($_POST['edition_term'])); 
$isbn_term = mysql_real_escape_string(htmlentities($_POST['isbn_term'])); 

if ($subject_term == 'Subject...'){ 
$subject = ''; 
} else {$subject = "`Subject` LIKE '%$subject_term%' AND";} 
if ($course_term == 'Number...'){ 
$course = ''; 
} else {$course = "`Course` LIKE '%$course_term%' AND";} 
if ($title_term == 'Book Title...'){ 
$title = ''; 
} else {$title = "`Title` LIKE '%$title_term%' AND";} 
if ($edition_term == 'Edition...'){ 
$edition = ''; 
} else {$edition = "`Edition` LIKE '%$edition_term%' AND";} 
if ($isbn_term == 'ISBN...'){ 
$isbn = ''; 
} else {$isbn = "`ISBN` LIKE '%$isbn_term%' AND";} 

$wc = "`ID`>='1'"; 

    $search = mysql_query("SELECT `Member`, `Subject`, `Course`, `Title`, `Edition`, `ISBN`, `Image`, `Condition`, `Price`, `Comments` FROM `Books` WHERE $subject $course $title $edition $isbn $wc"); 
    $result_count = mysql_num_rows ($search); 
    $suffix = ($result_count !=1) ? 's' : ''; 
    echo 'Your search for <strong>', $subject,'</strong> returned <strong>', $result_count,'</strong> result', $suffix; 

    while ($results_row = mysql_fetch_assoc($search)){ 
    echo '<div class="book-post"><div class="book-title"><h4>', $results_row['Title'],'.',$results_row['Edition'],'Edition</h4></div><div class="book-content"><span class="pullquote_left"><img src="', $results_row['Image'],'" width="100" height="100"/></span><span class="pullquote_right"><strong>Posted By:</strong><br/>', $results_row['Member'],'<br/><strong>Price:<br/></strong><em>$', $results_row['Price'],'</em><strong><br/>Condition:<br/></strong><em>', $results_row['Condition'],'Like New</em></span><strong>ISBN :</strong>', $results_row['ISBN'],'<br/><strong>Comments: </strong>', $results_row['Comments'],'.</div></div>';  
    } 
}else{ 
echo '<h3>Please log in to view textbook listings</h3>'; 
} 
?> 

アンソニー

+0

任意のJavaScriptのエラーがで問題を解決することができるのだろうか? – noob

+1

あなたの質問に対する答えではありませんが、HTML5のプレースホルダーシムを調べることができます。あなたのコードから膨大な量の複雑さ(すべてのonblur/onfocusとPHPのプレースホルダ値のテスト)を削除します。 – numbers1311407

+0

JavaScriptエラーはありません。 – Anthony

答えて

0

これはおそらく、答えではない...しかし、問題は、この種のデバッグに、放火犯を使用してください、お時間をいただき、ありがとうございますプラグイン。あなたは、サーバーに行く要求と変数が送信されるのを見て、検査することができます。また、js側で正しい値を読み込んでいるかどうかを確認するために、Firebugスクリプトタブにブレークポイントを設定します。あなたはジフィー:)

Get Firebug

+0

"これはおそらく答えではない"場合は、回答を追加する代わりにコメントを追加する必要があります。質問のコメントは、質問のポスターのバッジのすぐ下の質問の下部にあります。 –

+0

申し訳ありませんが、質問の下で「コメントを追加」オプションを見つけられませんでした...ただそのオプションを有効にするには50人の担当者が必要であることに気付きました! –

+0

私はこの問題を数時間トラブルシューティングしてきました。そして、私はデバッグにクロムを使用していますが、私はまだ自分の答えを考え出すことができませんでした。あなたはなにか考えはありますか? – Anthony