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>