我有一个提交表单,它将表单数据发布到名为invoice-detail.php
的文件中。在同一个实例中,我想调用一个函数来处理几个值。我尝试过相同但onClick
无效。
请检查下面的代码,建议我如何在同一个实例中执行这两个操作。
<?php include 'db.php'; ?>
<html>
<head>
<title>INVOICE Header</title>
<SCRIPT language=JavaScript>
function showda()
{
alert ("Show function !");
}
function showtin(str8)
{
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.open("GET","invtin.php?q8=" + str8,true);
xmlhttp.send();
}
function showcst(str10)
{
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.open("GET","invcst.php?q10=" + str10,true);
xmlhttp.send();
}
</script>
</head>
<body>
<?php
echo "<form name='form1' method='post' target='mainFrame' action='invoice-detail.php'>";
echo "<table width='829' height='100' border='0' align='center' cellpadding='0' cellspacing='2'>";
echo "<tr>";
echo "<td height='39' width='99' class='sty1'>Invoice No</td>";
$res=mysql_query("select * from INVHDR_draft WHERE usr='$user'");
$row = mysql_fetch_assoc($res);
$tincst=mysql_query("SELECT TIN_No, CST_No, ECC_No FROM ACMAST where Ac_code='$cat'");
$tincst2=mysql_fetch_assoc($tincst);
echo "<td width='140'><input name='Inv_no' type='text' size='6' maxlength='6' value='$row[Invno]' onBlur=\"if (this.value == '' || this.value == 0) {alert('Invoice No. is required'); f1.Inv_no.focus();}\" onchange=\"showinvno(this.value);\"></td>";
echo "</tr>";
echo "<tr>";
echo "<td height='39' width='99' class='sty1' valign='bottom'>TIN</td>";
echo "<td width='140' valign='bottom'><input name='tin' type='text' size='15' maxlength='15' value='$tincst2[TIN_No]' onchange=\"showtin(this.value);\"></td>";
echo "<td width='203' class='sty1' valign='bottom'>CST ";
echo " <input name='cst' type='text' size='15' maxlength='15' value='$tincst2[CST_No]' onchange=\"showcst(this.value);\"></td>";
echo "<td width='150' class='sty1' valign='bottom'>ECC No. ";
echo " <input name='ecc' type='text' size='15' maxlength='15' value='$tincst2[ECC_No]' onchange=\"showcst(this.value);\"></td>";
echo "</tr>";
echo "</table>";
echo " <input type='submit' name='Submit' value='Process!' onClick=\"'showda();\">";
echo "</form>";
?>
</body>
</html>
答案 0 :(得分:1)
您可以拨打onclick
来代码执行此代码,然后拨打formObject.submit()
function showda()
{
alert ("Show function !");
formObject.submit(); //get your form object by id or tagname
}
答案 1 :(得分:1)
而不是将onclick
添加到输入中,将onsubmit
添加到表单元素
echo "<form name='form1' method='post' target='mainFrame' action='invoice-detail.php'> onClick=\"'return showda();\">";
然后您可以更新showda()
方法:
function showda()
{
alert ("Show function !");
// do your actions here
// if they fail you can return false
return true;
}
答案 2 :(得分:0)
<?php include 'db.php'; ?>
<html>
<head>
<title>INVOICE Header</title>
<SCRIPT language=JavaScript>
function showda()
{
alert ("Show function !");
////////do your processing here before submit//////
document.form1.action="invoice-detail.php";
document.form1.submit();
}
function showtin(str8)
{
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.open("GET","invtin.php?q8=" + str8,true);
xmlhttp.send();
}
function showcst(str10)
{
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.open("GET","invcst.php?q10=" + str10,true);
xmlhttp.send();
}
</script>
</head>
<body>
<?php
echo "<form name='form1' method='post' target='mainFrame' action=''>";
echo "<table width='829' height='100' border='0' align='center' cellpadding='0' cellspacing='2'>";
echo "<tr>";
echo "<td height='39' width='99' class='sty1'>Invoice No</td>";
$res=mysql_query("select * from INVHDR_draft WHERE usr='$user'");
$row = mysql_fetch_assoc($res);
$tincst=mysql_query("SELECT TIN_No, CST_No, ECC_No FROM ACMAST where Ac_code='$cat'");
$tincst2=mysql_fetch_assoc($tincst);
echo "<td width='140'><input name='Inv_no' type='text' size='6' maxlength='6' value='$row[Invno]' onBlur=\"if (this.value == '' || this.value == 0) {alert('Invoice No. is required'); f1.Inv_no.focus();}\" onchange=\"showinvno(this.value);\"></td>";
echo "</tr>";
echo "<tr>";
echo "<td height='39' width='99' class='sty1' valign='bottom'>TIN</td>";
echo "<td width='140' valign='bottom'><input name='tin' type='text' size='15' maxlength='15' value='$tincst2[TIN_No]' onchange=\"showtin(this.value);\"></td>";
echo "<td width='203' class='sty1' valign='bottom'>CST ";
echo " <input name='cst' type='text' size='15' maxlength='15' value='$tincst2[CST_No]' onchange=\"showcst(this.value);\"></td>";
echo "<td width='150' class='sty1' valign='bottom'>ECC No. ";
echo " <input name='ecc' type='text' size='15' maxlength='15' value='$tincst2[ECC_No]' onchange=\"showcst(this.value);\"></td>";
echo "</tr>";
echo "</table>";
echo " <input type='submit' name='Submit' value='Process!' onClick='showda(); >";
echo "</form>";
?>
</body>
</html>
使用此代码