我有一个按钮(有人创建了它,我需要编辑),保存到employee.php中的$elisting
。该按钮将转到名为edit()
的javascript函数。 $elisting
代码如下:
$elisting ="";
$queryf = "select employee.id as myid,jobtitle,info,locid,deptid,gender,dob,emid,employee$cid.name,username,dept,datejoin,location.name as loc from employee
left join location on location$cid.id = employee.locid
inner join department on department.id = employee.deptid order by username
";
$resultf = pg_query($queryf);
$numrows = pg_numrows($resultf);
while ($rowf = pg_fetch_array($resultf)) {
$ct=$ct+1;
$myid = $rowf[myid];
$uname = $rowf[username];
$loc1 = $rowf[loc];
$dept = $rowf[dept];
$date = $rowf[datejoin];
$name = $rowf[name];
$emid = $rowf[emid];
$dob = $rowf[dob];
$gender = $rowf[gender];
$job = $rowf[jobtitle];
$info = $rowf[info];
$datejoin = $rowf[datejoin];
$locid = $rowf[locid];
$deptid = $rowf[deptid];
$newbal = $rowf[newbal];
$templatelist = "";
$tempcn = 0;
$querytemp = "select tid,ltype from leaveatemplate$cid where username='$uname' order by tid desc";
$resulttemp = pg_query($querytemp);
while ($rowtemp = pg_fetch_array($resulttemp)) {
$tempcn = $tempcn +1;
$tid = $rowtemp[tid];
$ltype = $rowtemp[ltype];
if($tempcn=="1")
$templatelist = "$ltype|$tid";
else
$templatelist = $templatelist.","."$ltype|$tid";
}
$elisting=$elisting."<tr><td align=\"center\">$uname</td><td align=\"center\">$loc1</td><td align=\"center\">$dept</td>
<td align=\"center\">$date</td>
<td align=\"center\"><a><button class=\"btn btn-mini\"data-toggle=\"modal\"href=\"#long\"
onClick=\"javascript:edit('$name','$uname','$emid','$dob','$gender','$job','$info','$datejoin','$locid','$deptid','$myid','$templatelist');\"><i class=\"icon-pencil\"></i></a>
以下是javascript edit()
代码:
function edit(a,b,c,d,e,f,g,h,i,j,k,l){
document.getElementById("frm").id.value=k;
document.getElementById("frm").name.value=a;
document.getElementById("frm").username.value=b;
document.getElementById("frm").emid.value=c;
document.getElementById("frm").dob.value=d;
setCheckedValue(document.forms['frm'].elements['gender'],e);
document.getElementById("frm").job.value=f;
document.getElementById("frm").info.value=g;
document.getElementById("frm").datejoin.value=h;
document.getElementById('locid').value=i;
document.getElementById('deptid').value=m;
var params = b;
window.location.href="http://192.168.1.5/eleave/employee.php?lapplicant=" + params;
var myTemp = l;
var mySplitResult = myTemp.split(",");
for(i = 0; i < mySplitResult.length; i++){
cval = mySplitResult[i];
myval = cval.split("|");
val1 = myval[0];
val2 = myval[1];
document.getElementById('temp'+val1).value= val2;
}
由于我未能尝试多种方式在b
中获取edit()
,因此我需要找到在$elisting
中获取$ uname并将其发送到$llisting
的方式在相同的PHP文件(employee.php)中,代码如下:
$llisting ="";
$ct=0;
//leave code
$ccompassionate = "3";
$cemergency = "4";
$cmaternity = "5";
$cmedical = "6";
$cannual = "2";
//leave value
$compassionate = 2;
$emergency = 5;
$maternity = 60;
$medical = 20;
$lapplicant = $_POST['lapplicant'];
$querye = "select leavetype.id, leavetype.ltype, leaves.leave from leavetype,leaves where username='".$_SESSION["username"]."'";
$resulte = pg_query($querye);
while ($rowe = pg_fetch_array($resulte)) {
$ct=$ct+1;
$lid = $rowe[id];
$ltype = $rowe[ltype];
$leave = $rowe[leave];
if ($lid == $ccompassionate) {
$compassionate_query = pg_query("select ltotal from leave where lapplicant='".$lapplicant."' and ltype='".$ccompassionate."'");
if (count($compassionate_query) > 0) {
foreach ($compassionate_query as $data) {
$total_compassionate = $total_compassionate + $data['total'];
$value = $compassionate - $total_compassionate;
}
} else {
$value = $compassionate;
}
$llisting=$llisting."<tr><td align=\"center\">$ct</td><td>$ltype</td><td><input type='text' value='$lapplicant'></td><td align=\"center\">";
$llisting=$llisting."<select name=\"temp$lid\" id=\"temp$lid\" class=\"span12\"><option value=\"0\"> - </option> $tlisting</select>";
$llisting=$llisting."</td></tr>\n";
任何人都有理由在$uname
中获取$elisting
并发送给$llisting
?
此外,'$name','$uname','$emid','$dob','$gender','$job','$info','$datejoin','$locid','$deptid','$myid','$templatelist'
中的$elisting
如何更改为a,b,c,d,e,f,g,h,i,j,k,l
中的edit()
,我是Javascript的新手,所以我不明白它怎么会改变?
感谢您的帮助..
这是href="#long"
调用的代码:
<div id="long" class="modal hide fade" tabindex="-1" data-replace="true" data-width="760">
<div class="modal-header"><h3>Employee Profile</h3></div>
<div class="modal-body">
<form class="form-horizontal" method="Post" name="frm" id="frm">
调用html页面的代码:
if($msg!="") $alert= "<div class=\"alert\"><i class=\"icon-info-sign\"></i> $msg</div><p> </p>";
$source2 = file_get_contents('http://'.$_SESSION["url"].'/cgi-bin/vo/'.$_SESSION["sessid"].'.interface.designer.vo?file=eleave/employee.htm');
$html2 = str_replace("[templateurl]",$templateurl,$source2);
$html2 = str_replace("[alert]",$alert ,$html2);
$html2 = str_replace("[elisting]",$elisting ,$html2);
$html2 = str_replace("[ulisting]",$ulisting ,$html2);
$html2 = str_replace("[locationlisting]",$locationlisting ,$html2);
$html2 = str_replace("[deptlisting]",$deptlisting ,$html2);
$html2 = str_replace("[llisting]",$llisting ,$html2);
$html2 = str_replace("[wfid]","sid=$sid" ,$html2);
echo $html2;
答案 0 :(得分:0)
请先尝试基本,我对此没有任何问题。
在JS中:
<script>
function TestTriggered(name){
alert("the function triggered!");
alert("My name is: " + name);
}
</script>
在HTML部分
<input type="button" name="myButton" onClick="javascript:TestTriggered('John');" value="Please click"/>
请先尝试一下,看看它是如何运作的。