2012-04-26 58 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