...

View Full Version : getting undefined using $_GET function



newphpcoder
01-03-2012, 01:24 AM
Hi..

I encountered problem in using $_GET to get the DATE_PROCESS.

here is my code:



<script>
function editloan(){

var dateprocess = document.getElementById('dateprocess').value;

alert(dateprocess);
window.location = "SSSLoan.php?dateprocess="+dateprocess;
}
</script>




<div id="searchname">
<form>
<p class="serif"><b>Search Lastname:</b></p>
<input type="text" name="ssssearch" size="20" onkeyup="fetchsuggest(this.value);">
<div>
<hr />
<ul id="suggest" style="overflow:auto; height:380px; width:auto;">
{section name=co_emp loop=$personalAll}
<li><a href="SSSgetdata.php?queryEmpID={$personalAll[co_emp].EMP_ID}">{$personalAll[co_emp].FULLNAME}</a></li>
<hr />
{sectionelse}
<li>No records found</li>
{/section}
</ul>
</div>
</div>
<div id="loanformmain">
<input type="button" name="sssbtn" value="SSS" onclick="loanFrm()">
<input type="button" name="hdmfbtn" value="HDMF" onClick="hdmfloanFrm()">
<input type="button" name="UTbtn" value="Union Dues/Trust Fund" onclick="utloanFrm()">
</div>
<div id="sssloan">
<fieldset>
<legend>SSS Loan</legend>
<p class="serif">
<label id="SSSLabel">SSS ID</label><label id="EMPIDLabel">EMP ID</label><label id="NAMELabel">NAME</label><label id="LOANLabel">LOAN</label><label id="AMORLabel">DEDUCTION</label>
<input type="text" name="SSS" value="{$sss}" size="8" style="background: #e2e2e2" readonly="readonly">
<input type="text" name="EMP_NO" value="{$empno}" size="8" style="background: #e2e2e2" readonly="readonly">
<input type="text" name="NAME" value="{$fullname}" style="background: #e2e2e2" readonly="readonly" size="35">
<input type="text" name="LOAN" value="{$LOAN}" size="9">
<input type="text" name="AMOR" value="{$AMOR}" size="9">
<input type="button" name="add" value="ADD" onclick="SSSAdd()">
<input type="hidden" name="dateprocess" value="{$dateprocess">
</p>
</legend>

</fieldset>
<div style="overflow:auto; height:300px; width:auto;">
<p>
<table border="1" class="stat">
<tr>
<td colspan="4" style="text-align:center">SSS ID</td>
<td colspan="4" style="text-align:center">EMP ID</td>
<td colspan="15" style="text-align:center">NAME</td>
<td colspan="4" style="text-align:center">LOAN</td>
<td colspan="4" style="text-align:center">DEDUCTION</td>
<td colspan="4" style="text-align:center">DATE PROCESS</td>

</tr>
{section name=att loop=$getsss}
<tr>
<td colspan="4" style="background: #e2e2e2" readonly="readonly">{$getsss[att].SSS}</td>
<td colspan="4" style="background: #e2e2e2" readonly="readonly">{$getsss[att].EMP_NO}</td>
<td colspan="15" style="background: #e2e2e2" readonly="readonly">{$getsss[att].FULLNAME}</td>
<td colspan="4" style="background: #e2e2e2" readonly="readonly">{$getsss[att].SSSLoan}</td>
<td colspan="4" style="background: #e2e2e2" readonly="readonly">{$getsss[att].SSSAmor}</td>
<td colspan="4" style="background: #e2e2e2" readonly="readonly" id="dateprocess" onclick="editloan('{$getsss[att].DATE_PROCESS}')">{$getsss[att].DATE_PROCESS}</td>
</tr>
{sectionelse}
<tr><td colspan="1">No DATA</td></tr>
{/section}

</table>
<table border="1">
<tr>
<td colspan="4" style="text-align:center"><b>TOTAL:</b></td> <td colspan="5" style="background: #e2e2e2" readonly="readonly">{$Total_Loan}</td>
</tr>
</table>
</p>
</form>
</div>
</div>




<?php
include 'config.php';

$currentEmpID = $_SESSION['empID'];

$sql = "SELECT EMP_ID, CONCAT(LNAME, ', ', FNAME, ' ', MI, '.') AS FULLNAME, SSS, HDMF, TIN FROM PERSONAL WHERE EMP_ID='$currentEmpID'";
$recPersonal = $conn->Execute($sql);

if (!$recPersonal) {
print $conn->ErrorMsg();
}

if (!$recPersonal->BOF) {
$recPersonal->MoveFirst();
}

$sss = trim($recPersonal->fields['SSS']);
$hdmf = trim($recPersonal->fields['HDMF']);
$tin = trim($recPersonal->fields['TIN']);

$smarty->assign('sss', $sss);


$sql = "SELECT EMP_ID, CONCAT(LNAME, ', ' , FNAME, ' ', MI) AS FULLNAME FROM PERSONAL ORDER BY LNAME ASC";
$recPersonalNav = $conn->GetAll($sql);
$smarty->assign('personalAll', $recPersonalNav);
// ==================================================================================================== ====================

$sql = "SELECT em.EMP_NO, p.EMP_ID, CONCAT(LNAME, ', ', FNAME, ' ', MI, '.') AS FULLNAME FROM PERSONAL p, EMPLOYMENT em WHERE p.EMP_ID='$currentEmpID' AND em.EMP_ID = '$currentEmpID'";

$recPersonalHead = $conn->Execute($sql);
$fullName = $recPersonalHead->fields["FULLNAME"];
$empno = $recPersonalHead->fields["EMP_NO"];

$smarty->assign('empid', $currentEmpID);
$smarty->assign('fullname', $fullName);
$smarty->assign('empno', $empno);

//===============================SELECT SSSLoan===================================
$dateprocess = $_GET['dateprocess'];

$sql = "SELECT s.EMP_NO, s.SSSLoan, s.SSSAmor, s.DATE_PROCESS FROM $PAYROLL.sssloan s, $ADODB_DB.employment em WHERE em.EMP_NO= s.EMP_NO AND s.DATE_PROCESS = '$dateprocess'";
$rsloan = $conn2->Execute($sql);

$LOAN = trim($rsloan->fields['SSSLoan']);
$AMOR = trim($rsloan->fields['SSSAmor']);

$dateprocess = $rsloan->fields['DATE_PROCESS'] ;

$smarty->assign('LOAN', $LOAN);
$smarty->assign('AMOR', $AMOR);
$smarty->assign('dateprocess', $dateprocess);

//============================SELECT ALL DATA FOR SSSLOAN==========================
$sql = "SELECT s.EMP_NO, em.EMP_ID, p.SSS, CONCAT(LNAME, ', ', FNAME, ' ', MI, '.') AS FULLNAME, s.SSSLoan, s.SSSAmor, s.DATE_PROCESS FROM $ADODB_DB.PERSONAL p, $ADODB_DB.employment em, $PAYROLL.sssloan s WHERE s.EMP_NO = em.EMP_NO AND p.EMP_ID = '$currentEmpID' AND em.EMP_ID = '$currentEmpID'";

$rs = $conn2->GetAll($sql);

$smarty->assign('getsss', $rs);

$sql = "SELECT s.EMP_NO, SUM(SSSAmor) AS Total_Loan FROM $PAYROLL.sssloan s, $ADODB_DB.employment em WHERE em.EMP_NO = s.EMP_NO AND em.EMP_ID = '$currentEmpID'" or die (mysql_error());
$rsTotal = $conn2->Execute($sql);

$Total_Loan = $rsTotal->fields['Total_Loan'];

$smarty->assign('Total_Loan', $Total_Loan);

$smarty->display('header.tpl');
$smarty->display('loanForm.tpl');
$smarty->display('footer.tpl');
exit();
?>


when I click date in <td colspan="4" style="background: #e2e2e2" readonly="readonly" id="dateprocess" onclick="editloan('{$getsss[att].DATE_PROCESS}')">{$getsss[att].DATE_PROCESS}</td>

it result no value...it did not get the value that I click

Thank you in advance

_Aerospace_Eng_
01-03-2012, 01:39 AM
This is more of a javascript problem than a php one. It doesn't get the value because it is a td element not a form input. A td element does not have a "value" property. Try this instead

var dateprocess = document.getElementById('dateprocess').firstChild.nodeValue;

tangoforce
01-03-2012, 01:42 AM
This is more of a javascript problem than a php one.

Careful AE, I can't remember why but I added this user to my ignore list ages ago. Only reason I still reply sometimes is because the main list still shows this persons topics (yet when I click into it, the forum hides the opening post :rolleyes:)

newphpcoder
01-03-2012, 01:51 AM
This is more of a javascript problem than a php one. It doesn't get the value because it is a td element not a form input. A td element does not have a "value" property. Try this instead

var dateprocess = document.getElementById('dateprocess').firstChild.nodeValue;

I tried this, but the problem is only the first date was get.

Thank you...

i have date:

2011-12-18
2011-12-20
2011-12-28
when i click 2011-12-28 the displayed date is 2011-12-18

Thank you

newphpcoder
01-03-2012, 02:14 AM
i also tried this:



var dateprocess = document.getElementById('dateprocess').innerHTML;


but still the first date only was displayed even i click the last date...:confused:

Thank you

_Aerospace_Eng_
01-03-2012, 02:44 AM
Right because you are only supposed to have one element with id="dateprocess", not multiple like you have. Just change this

function editloan(){

var dateprocess = document.getElementById('dateprocess').value;

alert(dateprocess);
window.location = "SSSLoan.php?dateprocess="+dateprocess;
}
to this

function editloan(thedate){

var dateprocess = thedate;

alert(dateprocess);
window.location = "SSSLoan.php?dateprocess="+dateprocess;
}
So again this is a javascript problem not a php one.

newphpcoder
01-03-2012, 02:51 AM
Thank you...it works...can you explain me the used of

thedate?


Thank you

Spookster
01-03-2012, 03:26 AM
Moving to JS forum...

_Aerospace_Eng_
01-03-2012, 03:36 AM
In your output you had onclick="editloan(some date here)", so to use document.getElementById you had to pass in the ID of the current element. You weren't doing that. You were passing in the date yet your function didn't accept any arguments. thedate is an argument to your editloan function although you should probably be passing in the ID of the loan and not the date. What if you have more than one loan on the same date.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum