0

我有一个包含 7 列的表(投诉 ID、姓名、学校名称等),还有一个按钮。当我单击按钮时,我需要将该行的投诉 ID 传递到另一个页面。问题是值没有在 ajax 页面中传递。

<html>
<body>

?>
<form  action="" name="frmcomplaint" id="frmcomplaint" method="post">
<table border="1" style="border-color: #FFFFFF;" >
    <tr>
            <th style="color: #FF0000">Sl. No</th>
        <th style="color: #FF0000">Complaint Id</th>
        <th style="color: #FF0000">Date</th>
        <th style="color: #FF0000; width:200px;" >Name Of student</th>
        <th style="color: #FF0000">District</th>
        <th style="color: #FF0000">School Name</th>
        <th style="color: #FF0000">Standard with </th>
        <th style="color: #FF0000; width:200px;">Complaint</th>

    </tr>


<?php
while($row=mysql_fetch_array($result))
{
    $date1=explode('-', $row[$i+2]);
    $entrydate=$date1[2]."-".$date1[1]."-".$date1[0];
    $job_id=$row[$i+1];
?>
    <tr>
        <td style="color: #000000"><?php echo $j;?></td>
        <td style="color: #000000"><?php echo $row[complain_Id]; ?> </td>
        <td style="color: #000000"><?php echo $entrydate;?></td>
        <td style="color: #000000" ><?php echo $row[studname];?></td>
        <td style="color: #000000"><?php echo $row[District];?></td>
        <td style="color: #000000"><?php echo $row[School_name] ;?></td>
        <td style="color: #000000"><?php                                  echo $ row[Standard]."-".$row[Division];?></td>
        <td id="disp" ><?php echo $row[Complaint];?></td>
        <td id="button" name="viewbutton" >
            <input type="button" value="View" class="button" id="'<?php  $button; ?>'"  onclick="selectedjob(alert('hi there')<?php $job_id ?>)">
         </td>

    </tr>

<?php
$button++;
$j=$j+1;
}


?>
    <input type='hidden' value='view' class='button' name="selectedjob" id="selectedjob">
</table>
</form>
    <script type="text/javascript">
             function selectjob(jobid)
                    {
                            $('#selectedjob').val(jobid);
                            $('#frmSelectJob').attr('action', 'careers-apply.php');
                            $('#frmSelectJob').attr('method', 'post');
                            $('#frmSelectJob').submit();




                    }
</body>
</html>
4

2 回答 2

0

您可以使用 jquery 来完成。我为你编写简单的代码。我试试看。它应该工作

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script type="text/javascript" >
jQuery(document).ready(function(){
<?php
//  $num_rows=mysql_num_rows(query result)
$num_rows=10;
for($i=1;$i<$num_rows+1;$i++)
{

?>
$("#button_<?=$i?>").click(function(){
    //alert("hi");
    var complain_Id = $("#complain_Id_<?=$i?>").val();
    if($("#complain_Id_<?=$i?>").val()=='') complain_Id="";

    var dataString = 'complain_Id='+ complain_Id;

        $.ajax({
        type: "POST",
        url: "getresult.php",
        data: dataString,
        success: function(msg){         
  $('#count_display').html(msg);                        
        }
        }); //END $.ajax                
  });
      <?php
      }
      ?>
      });
      </script>
      <html>
      <body>
      <?php

       ?>
       <form  action="" name="frmcomplaint" id="frmcomplaint" method="post">
       <table border="1" style="border-color: #FFFFFF;" >
       <tr>
        <th style="color: #FF0000">Sl. No</th>
        <th style="color: #FF0000">Complaint Id</th>
       <th style="color: #FF0000">Date</th>
       <th style="color: #FF0000; width:200px;" >Name Of student</th>
       <th style="color: #FF0000">District</th>
       <th style="color: #FF0000">School Name</th>
       <th style="color: #FF0000">Standard with </th>
       <th style="color: #FF0000; width:200px;">Complaint</th>

       </tr>


       <?php
       $button=1;
       //while($row=mysql_fetch_array($result))
       for($i=1;$i<11;$i++)
       {
       /* $date1=explode('-', $row[$i+2]);
       $entrydate=$date1[2]."-".$date1[1]."-".$date1[0];
       $job_id=$row[$i+1];*/
       ?>
       <tr>
       <td style="color: #000000" ><?php echo $i;?></td>
       <td style="color: #000000" id="comid"><?php echo $i; ?>
       <input type="hidden" name="complain_Id_<?=$i?>" id="complain_Id_<?=$i?>" value="<?=$i?>"/> </td>
       <td style="color: #000000"><?php echo $i+2;?></td>
       <td style="color: #000000"><?php echo $i+3;?></td>
       <td style="color: #000000"><?php echo $i+4;?></td>
       <td style="color: #000000"><?php echo $i+5;?></td>
       <td style="color: #000000"><?php echo $i+6;?></td>
       <td id="disp" ><?php echo $i+7;?></td>
       <td id="button" name="viewbutton" >
        <input type="button" value="View" class="button_<?=$i?>" id="button_<?=$i?>"  />
       </td>

       </tr>

      <?php
      //$button++;
      //$j=$j+1;
      }

      ?>    
      </table>
      </form>
      <div id="count_display" >
      </div>
      </body>
      </html>

display.php 的代码

<?php
$complain_Id=$_POST['complain_Id'];
echo "complain_Id=".$complain_Id;
?>

请根据需要更改代码。我使用隐藏的输入字段来保存抱怨 ID 值

于 2013-11-06T12:31:51.040 回答
0

尝试这个。你需要回声

<input type="button" value="View" class="button" id="'<?php echo $button; ?>'"  onclick="selectedjob(<?php echo $job_id; ?>)">

编辑

你可以像这样传递jobid

function selectjob(jobid)
{
    window.location.href = "display.php?jobid=" + jobid;
}

在 display.php 中获取作业 ID 作为$_GET['jobid']

于 2013-11-06T10:25:40.133 回答