2011-12-16 4 views
0
while ($row1 = mysql_fetch_array($event1)) 
{ 

    $event = $row1['post']; 
    $timeposted = $row1['date']; 

    $eventmemdata = mysql_query("SELECT id,firstname FROM users WHERE id = '$id' LIMIT 1"); 

    while($rowaa = mysql_fetch_array($eventmemdata)) 
    { 
    $name = $rowaa['firstname']; 
    $eventlist = "$event <br> $name"; 
    } 


echo " <div id = 'eventer'> $timeposted <br>$eventlist</div> <input name='myBtn'  type='submit' value='increment' onClick='javascript:ajax_post();'> 
<input name='lol' type='submit' value='dec' onClick='javascript:ajax_posta();'> 
<div id = 'status'>lol</div>"; 
echo "<br>"; 


} 

?> 

ボタンがクリックされたdivを確認する必要があります。これはajax関数です。phpタグにnumをエコーする必要がありますボタンがクリックされたクラス/ポストはwhileループであり、ボタンの多くのレプリカがあります。右のdivを選択するには

<script language="JavaScript" type="text/javascript"> 
var num = 1; 

function ajax_post(){ 
// Create our XMLHttpRequest object 
var hr = new XMLHttpRequest(); 
// Create some variables we need to send to our PHP file 
var url = "javas.php"; 



hr.open("POST", url, true); 
// Set content type header information for sending url encoded variables in the request 
hr.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); 
// Access the onreadystatechange event for the XMLHttpRequest object 
hr.onreadystatechange = function() { 
    if(hr.readyState == 4 && hr.status == 200) { 
     var return_data = hr.responseText; 
     document.getElementById("status").innerHTML = return_data; 
    } 
} 
// Send the data to PHP now... and wait for response to update the status div 
hr.send("num=" + (++num)); // Actually execute the request 
document.getElementById("status").innerHTML = "processing..."; 

} 

ボタンをクリックした特定の部門に情報/データを表示するにはどうしたらいいですか?私は今それを持っているので、エコーは、それが拾うファーストクラスで行われます! 非常に感謝しています!

+2

ありませんなぜjQueryタグがそこにあるのか、あなたが提供したコードではjQueryが使用できないことは明らかです。 –

+1

@Topener彼らはjQueryを使って回答に興味があるかもしれません。 –

答えて

0

私が正しく理解していると、複数のボタンが押され、魔女が押されたことを知りたいと思っています。

function(){ whateverFunctionYouUsed(this)} 

のonclickイベントにこれを追加またはあなたがちょうどあなたがあなたの関数に送信する前に、必要な属性を取得することができます。

あなたがFirefoxの+の放火犯は、オブジェクトのすべてのプロパティを見ると、あなたが必要なものを取るためにこれを使用している場合:

function(){ 
      console.log(this) 
      whateverFunctionYouUsed(this) 
    } 
0

jQueryを使って、それは非常に簡単です:

$("yourContainerId > div").click(function() { 
    var index = $("div").index(this); 
    alert(index); 
}); 

http://api.jquery.com/index/

関連する問題