Re: Loop problem

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



   I know you said it's a form.... but where does the browser realize that?

   Using a hidden value such as that would require a POST or GET action via
a form.  JavaScript wouldn't work for that.  However, you could do something
like this:

<snip>
<SCRIPT LANGUAGE="JavaScript">
function showAlert(id,type) {
       alert('The type is:' + type + ' - The ID is:' + id);
}
</SCRIPT>
<?
while($row_payments = mssql_fetch_array($result_payments)) {
       extract($row_payments);
       $total += $payment_amount;
?>
       <tr>
               <td width="21">ID:</td>
               <td width="88"><a
href="javascript:showAlert('<?=$child_support_id;?>','C')"><?=$child_support_id;?></a></td>
               <td width="98">Case Number:</td>
               <td width="252"><?=$case_number;?></td>
               <td width="116"><div align="right">Payment
Amount:</div></td>
               <td width="105"><div
align="right">$<?=number_format($payment_amount,2);?></div></td>
       </tr>
<?
</snip>

   If 'C' isn't a constant, but rather a dynamic value from a column in a
database (named the same as the convention in your example suggests), then
simply modify it as such:
<td width="88"><a
href="javascript:showAlert('<?=$child_support_id;?>','<?=$request_type;?>')"><?=$child_support_id;?></a></td>

   That should do it for you.


On 5/4/07, Dan Shirah <mrsquash2@xxxxxxxxx> wrote:

Okay, I think this is a 1/2 PHP problem and 1/2 Javascript problem.  And I
think my Javascript problem is being caused by my PHP.  Follow?

The code below is a loop of records returned from my query:

1 - If the result is not empty it will loop through the results.
2 - It assigns variables based on columns from the query.
3 - The first column of the row is the ID which is used by the Javascript
to
pull up the correct record.
4 - I put in a hidden value to assign all the rows in this loop a
"request_type" value.
5 - When someone clicks on a record ID it calls the Javascript to "alert"
the ID and request_type.
6 - If the loop only returns a single record, the "alert" displays
correctly.  Example: The type is:C The ID is:80
7 - If the loop returns multiple records, the "alert" does not return the
correct values.

Example: The type is:undefined The ID is:80
               The type is:undefined The ID is:85
               The type is:undefined The ID is:104

Why do I only get "undefined" if the loop returns more than a single
record???

***The Javascript***

function showAlert(id) {
var type;
type = document.Submit.request_type.value

alert( 'The type is:' + type + 'The ID is:' + id );
}

***The Form***

<table align="center" border="0" cellpadding="0" cellspacing="0"
width="680">
<?php
if(!empty($result_payments)) {
while ($row_payments = mssql_fetch_array($result_payments)) {
   $id = $row_payments['child_support_id'];
   $case_number = $row_payments['case_number'];
   $payment_amount = $row_payments['payment_amount'];
   $total += $row_payments['payment_amount'];
?>

  <tr>
    <td width="21">ID:</td>
    <td width="88"><?php echo "<a
href='javascript:showAlert($id)'>$id</a>"
?></td>
    <td width="98">Case Number:</td>
    <td width="252"><?php echo $case_number; ?></td>
    <td width="116"><div align="right">Payment Amount:</div></td>
    <td width="105"><div align="right">$<?php echo
number_format($payment_amount, 2); ?></div></td>
    <input type="hidden" name="request_type" value="C">
  </tr>

<?php
    }
}
?>
</table>

--
Daniel P. Brown
[office] (570-) 587-7080 Ext. 272
[mobile] (570-) 766-8107

[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux