2012-04-26 57 views
0

我使用的查詢,通過使用一個循環來填充消息列表,這裏是我的代碼:發送輸入數組中特定的輸入值轉換爲JavaScript

<?php 
$sql_i_msg_sent_waiting="SELECT t1.i_message_id,t2.username,t2.name,t2.propic,t2.age,t2.dob,t3.religion,t3.caste 
FROM candidate_i_message as t1, candidate_register_table as t2, candidate_social_table as t3 WHERE t1.from_username='$_SESSION[logged_user]' AND t1.to_username=t2.username AND t2.username=t3.username AND t1.status='0'"; 
$result_i_msg_sent_waiting=mysql_query($sql_i_msg_sent_waiting,$con); 
$count=mysql_num_rows($result_i_msg_sent_waiting); 
echo $count; 

?> 



<div id="section_i_message_sent_waiting" style="width:650px; overflow:auto;"> 
     <h2>Awaiting Sent Request</h2> 
      <?php 
      if(mysql_num_rows($result_i_msg_sent_waiting)==0) 
      { 
      ?> 
      <div style="width:650px; border-bottom:1px solid #CCCCCC" align="center"> 
      <table border='0' cellspacing='0' cellpadding='0' width='550px' align='center'> 
      <tr style='padding-botton:5px; border-bottom:1px solid #CCCCCC'> 
      <td width='50px'/> 
      <td><FONT COLOR=red FACE='Geneva, Arial' SIZE=2> 
         No Messages Found.</FONT></td> 
        <td width='50px'/></tr></table> 
      </div>  

     <?php 
     } 
     else 
     { 
     while($row_i_msg_sent_waiting=mysql_fetch_array($result_i_msg_sent_waiting)) 
     { 
     ?> 
     <div style="width:650px; border-bottom:1px solid #CCCCCC" align="center"> 
      <table width="550px" cellpadding="0" cellspacing="0" border="2" align="center" style="vertical-align:middle"> 
      <tr style='vertical-align:middle'> 
      <td style='vertical-align:middle' width="100px"> 
      <form method='post' action='id.php' name='showid' id='showid'> 
      <input type='hidden' name='pro_username' id='pro_username' 
      value="<?php echo $row_i_msg_sent_waiting['username'];?>"/> 
        <input type='image' src='<?php echo $row_i_msg_sent_waiting['propic'];?> ' style="width:100px; vertical-align:middle"/> 
     </form> 
      </td> 
      <td style='vertical-align:middle;border-right:1px solid #CCCCCC;border-top:1px solid #CCCCCC' width="450px" > 
       <table width="450px" cellpadding="0" cellspacing="0" border="0"> 
       <tr> 
       <td width="10px"/> 
       <td width="100px" align="left">Name</td> 
       <td width="10px">:</td> 
       <td width="100px" align="left"><?php echo $row_i_msg_sent_waiting['name'];?> 
       </td> 
       <td width="10px"> 
       <td width="100px" align="left">Age</td> 
       <td width="10px">:</td> 
       <td width="100px" align="left"><?php echo $row_i_msg_sent_waiting['age'];?> 
       </td> 
       <td width="10px"/> 
       </tr> 
        <tr> 
       <td width="10px"/> 
       <td width="100px" align="left">Date Of Birth</td> 
       <td width="10px">:</td> 
       <td width="100px" align="left"><?php echo $row_i_msg_sent_waiting['dob'];?> 
       </td> 
       <td width="10px"> 
       <td width="100px" align="left">Religion</td> 
       <td width="10px">:</td> 
       <td width="100px" align="left"><?php echo $row_i_msg_sent_waiting['religion'];?> 
       </td> 
       <td width="10px"/> 
       </tr> 
       <tr> 
       <td width="10px"/> 
       <td width="100px" align="left">Caste</td> 
       <td width="10px">:</td> 
       <td width="100px" align="left"><?php echo $row_i_msg_sent_waiting['caste'];?> 
       </td> 
       <td width="10px"> 
       <td width="100px" align="left">Religion</td> 
       <td width="10px">:</td> 
       <td width="100px" align="left"><?php echo $row_i_msg_sent_waiting['religion'];?> 
       </td> 
       <td width="10px"/> 
       </tr> 
       <tr> 
       <td width="10px"/> 
       <td width="100px" align="left">Action</td> 
       <td width="10px">:</td> 
       <td width="100px" align="left"> 
       <form method="post" name="cancel_request_form" id="cancel_request_form" 
       action="javascript:cancel_request(document.getElementById('cancel_request_form'));"> 
       <input type="text" name="no_of_msg" id="no_of_msg" value="<?php echo $count;?>"/> 
        <input type="text" name="cancel_request[]" id="cancel_request[]" 
        value="<?php echo $row_i_msg_sent_waiting['i_message_id'];?>"/> 
        <input type="submit" name="cancel" id="cancel" class="button" style="width: 100px" value="Cancel Request"/> 
        </form> 
       </td> 
       <td width="10px"> 
       <td width="100px" align="left"></td> 
       <td width="10px">:</td> 
       <td width="100px" align="left"> 
       </td> 
       <td width="10px"/> 
       </tr> 
          </table> 
      </td> 
      </tr> 

      </table> 
     </div> 
     <?php 
     } 
     }?> 

</div> 

<input type="text" name="cancel_request[]" id="cancel_request[]" 
        value="<?php echo $row_i_msg_sent_waiting['i_message_id'];?>"/> 

       creates a array of input type text, and each input text contains corressponding message_id...since each input text is contained within a form, and since the form is within a loop, the form is also repeatative..when the submit button will be clicked corressponding to a particular form, the input type text[] within that form will fire the value to get accepted in the javascript i give below... 

<script> 
function cancel_request(obj) { 

alert(document.getElementByName('cancel_request[]').value); 
} 
</script> 

但腳本顯示問題,它根本不工作。我不知道什麼是錯的。它不顯示任何東西。有MESSAGE_ID 1和2:一個文本類型的輸入[]包含值1,另一個值2

當我點擊提交按鈕對應於值1時,該文本類型的輸入的值將被髮送到JavaScript和顯示。我的腳本有什麼問題?

+0

是啊,實際上這並不在我的腦海裏,好的下一次,我會記住這一點 – Saswat 2012-04-26 13:19:29

回答

1

功能是getElementsByName - 複數中的元素。然後你可以像數組一樣訪問它。

+0

Thanx爲此,我沒有知道該代碼 – Saswat 2012-05-01 03:37:52