当前页面: JAVA 编程资料牛鼻论坛 → AJAX & JavaScript 技术→关于javasrcipt与PHP相互访问数组的问题~高手进来 |
只有一行时,javascript脚本也运行了,但是这时候document.fm1.t_uprice.length值没有定义,判断一下就可以了。
for($line=1;$line<=$max_line;$line++)
{
echo "<input name='amount' type='text'> ";
echo "<input name='price' type='text' onChange="return calc_lineprice();" > ";
echo "<input name='totalprice' type='text' readonly>";
}
echo "<input name='t_price' type="hidden" id="t_price"> //该隐含变量的作用是将用户输入的所有单价组合成一个用,隔开的一组变量,就是asp中处理同名变量的手法。
<script language="JavaScript" type="text/JavaScript">
function calc_lineprice()
{
var t_lineprice=0;
var t_price="";
if (!document.fm1.price.length)
{ //如果只有一行,则用此程序处理
t_lineprice=document.fm1.amount.value*document.fm1.price.value;
t_price=t_unitprice+document.fm1.price.value+",";
document.fm1.totalprice.value=t_lineprice;
}
else
{
for(var i=0;i<document.fm1.price.length;i++)
{
t_lineprice=document.fm1.amount[i].value*document.fm1.price[i].value;
t_price=t_price+document.fm1.price[i].value+",";
document.fm1.totalprice[i].value=t_lineprice;
}
document.fm1.t_price.value=t_price;
}
</script>
只有一行时,javascript脚本也运行了,但是这时候document.fm1.t_uprice.length值没有定义,判断一下就可以了。
for($line=1;$line<=$max_line;$line++)
{
echo "<input name='amount' type='text'> ";
echo "<input name='price' type='text' onChange="return calc_lineprice();" > ";
echo "<input name='totalprice' type='text' readonly>";
}
echo "<input name='t_price' type="hidden" id="t_price"> //该隐含变量的作用是将用户输入的所有单价组合成一个用,隔开的一组变量,就是asp中处理同名变量的手法。
<script language="JavaScript" type="text/JavaScript">
function calc_lineprice()
{
var t_lineprice=0;
var t_price="";