Jazlyn Jazlyn - 5 months ago 9
PHP Question

Pass Php value to javascript URL (only showing 1 record)

Need help on below coding.
I got a problem in

index.php
file:

$button = $_GET['submit'];

//search for invoice no
$search = $_GET['search'];
if(!$button){
echo "you didnt submit invoice no";
}
else{
if(strlen($search)<=1)
echo "search term too short";
else {
echo "you searched for <b> $search </b><hr size='1'></br> ";
$search_exploded =explode(" ",$search);

}


?>


<script src="/js/jquery.js"></script>
<script type="text/javascript" src="/js/jquery-ui.min.js"></script>
<link rel="stylesheet" type="text/css" media="screen"
href="/css/jquery-ui.css">
<link href="/css/formCss.css" rel="stylesheet" type="text/css"/>
<link type="text/css" rel="stylesheet" href="/css/nova.css"/>
<script type="text/javascript">




//datepicker
$(function () {
$('.date-picker1').datepicker({ dateFormat: 'yy-mm-dd' }).val();

}
);



</script>

<html>

<head>

<h2 id="header_1" class="form-header" style="font-size:21px">
<center>
<image src='/image/logo.gif'/>
</center>
<center>Edit Manual Tax Invoice</center>
</h2>

</head>


<?php


$rb = $connect->Execute("SELECT * FROM IT_Dept.dbo.testingHeader A LEFT JOIN IT_Dept.dbo.testingDetail B
ON A.invoiceno=B.invoiceno_dt
WHERE A.invoiceno = '".$search."'");



}

$invoiceno = $rb->Fields("invoiceno");
$company = $rb->Fields("company");
$custname = $rb->Fields("custname");
$remarks = $rb->Fields("remarks");
$custadd = $rb->Fields("custadd");
$date = $rb->Fields("date");
$acccode = $rb->Fields("acccode");



$newadd=str_replace("<br />","\n",$custadd);
//table details




?>


<body>

<form id="formheader">
<table id="table1" align="center" width="100%">


<tr>
<td width="20%">
Invoice No.
</td>
<td width="80%"><input name="invoiceno" id="invoiceno" value = "<?php echo $invoiceno; ?>"></td>
</tr>

<tr>
<td width="20%">
Company.
</td>
<td width="80%" >
<input name = "company" id="company" style="width: 40%;" value = "<?php echo $company; ?>">
</td>
</tr>

<tr>
<td width="20%">
Date.
</td>
<td width="80%" >
<input name = "date" id="date" style="width: 40%;" value = "<?php echo $date; ?>">
</td>
</tr>

<tr>
<td width="20%">
Account Code.
</td>
<td width="80%" >
<input name = "acccode" id="acccode" style="width: 40%;" value = "<?php echo $acccode; ?>">
</td>
</tr>

<tr>
<td width="20%">
Customer Name.
</td>
<td width="80%" >
<input name = "custname" id="custname" style="width: 40%;" value = "<?php echo $custname; ?>">
</td>
</tr>

<tr>
<td width="20%">
Customer Address.
</td>
<td width="80%" >
<textarea name = "custadd" id="custadd" style="width: 40%; height: 100%;"><?php echo $newadd ; ?></textarea>
</td>
</tr>

<tr>
<td width="20%">
Remarks.
</td>
<td width="80%" >
<textarea id="remarks" name ="remarks" style="width: 40%;" ><?php echo $remarks; ?></textarea>
</td>
</tr>


</table>

</form>

<?php

echo "<form id= 'form2' method='post'><table id='tabledesc' border=1>
<tr>
<th>Description </th>
<th>Qty</th>
<th >Unit Price(Before GST)</th>
<th>Total(Before GST)</th>
<th >*Total GST</th>
<th >Amount(RM)</th>
<th >Tax input/output</th>
<th >Debit Acc</th>
<th >Credit Acc</th>
<th >T1</th>
<th >T2</th>
<th >T3</th>
<th >T4</th>
<th >Tax Code</th>
<th > </th>
<th > </th>
</tr>";
// $x=1;
while(!$rb->EOF) {

$description = $rb->Fields("description");
$invoiceno_dt = $rb->Fields("invoiceno_dt");
$runningno = $rb->Fields("runningno");
$qty = $rb->Fields("qty");
$unitprice = $rb->Fields("unitprice");
$totalb4gst = $rb->Fields("totalb4gst");
$gst = $rb->Fields("gst");
$amount = $rb->Fields("amount");
$taxtype = $rb->Fields("taxtype");
$debitacc = $rb->Fields("debitacc");
$creditacc = $rb->Fields("creditacc");
$ta = $rb->Fields("ta");
$tb = $rb->Fields("tb");
$tc = $rb->Fields("tc");
$td = $rb->Fields("td");
$taxcode = $rb->Fields("taxcode");


$description = $description->value;
$invoiceno_dt = $invoiceno_dt->value;
$runningno = $runningno->value;
$qty = $qty->value;
$unitprice = $unitprice->value;
$totalb4gst = $totalb4gst->value;
$gst = $gst->value;
$amount = $amount->value;
$taxtype = $taxtype->value;
$debitacc = $debitacc->value;
$creditacc = $creditacc->value;
$ta = $ta->value;
$tb = $tb->value;
$tc = $tc->value;
$td = $td->value;
$taxcode = $taxcode->value;
echo "<tr><td>".$description."</td>";
echo "<td>".$qty."</td>";

echo "<td>".$unitprice."</td>";
echo "<td>".$totalb4gst."</td>";
echo "<td>".$gst."</td>";
echo "<td>".$amount."</td>";
echo "<td>".$taxtype."</td>";
echo "<td>".$debitacc."</td>";
echo "<td>".$creditacc."</td>";
echo "<td>".$ta."</td>";
echo "<td>".$tb."</td>";
echo "<td>".$tc."</td>";
echo "<td>".$td."</td>";
echo "<td>".$taxcode."</td>";
echo "<input type='hidden' name = 'runningno' id='runningno' value = ' $runningno ' >";


echo "<td><button onclick='openedit()'>Edit</button></td>";
//echo "<td><a href='edit.php?invoiceno_dt=".$invoiceno_dt."&runningno=".$runningno."'>Edit</a></td>";
//echo "<td><a href='delete.php?invoiceno_dt=".$invoiceno_dt."&runningno=".$runningno."'>x</a></td><tr>";

echo "<td><button onclick='opendelete()'>Delete</button></td>";

$rb->MoveNext();

}



?>

</table></form></body>





<script type="text/javascript">




var popup;


function openedit() {


var myinvoice = document.getElementById("invoiceno").value;
// var myrunningno = document.getElementById("runningno").value;
var no = <?php echo $runningno; ?>;
alert(no);
//alert(myrunningno);
popup = window.open("edit.php?invoiceno="+myinvoice+'&runningno='+no, "Popup", "width=500,height=600");
popup.focus();
}

function opendelete() {
var myinvoice = document.getElementById("invoiceno").value;
var myrunningno = document.getElementById("runningno").value;
//alert(myrunningno);
popup = window.open("delete.php?invoiceno_dt="+myinvoice+'&runningno='+myrunningno, "Popup", "width=500,height=600");
popup.focus();
}



</script>
<?php




$rb->close;

$connect->close;

$rb=null;
$connect =null;


?>


However I got few running no, when I press edit button it only show running no '1', other running no like 2 or 3 also showing running no 1 when i press edit on the row 2 and row 3.

Answer

You could add the running number to the page for example by doing this:

<script type="text/javascript">
    var no = <?php echo $runningNo; ?>;
</script>