js
<script language="javascript">
function Checknull()
{
var head="ShoppingCar1_";
var table = document.getElementById(head+"dataGrid");
var cTR = table.getElementsByTagName("TR");
var str="";
var UseGprice=0;
var UseHprice=0;
var re =/^/+?[1-9][0-9]*$/;
for (i = 1; i < cTR.length-1; i++)
{
var tr = cTR.item(i);
str = tr.cells[3];
var input = str.getElementsByTagName("input");
str2=tr.cells[4];
var input2 = str2.getElementsByTagName("input");
//判斷是否為正整數 /^/+?[1-9][0-9]*$/
if (!re.test(input[0].value))
{
input[0].value=0;
}
if (!re.test(input2[0].value))
{
input2[0].value=0;
}
if((input[0].value!=""&&input[0].value!="0" )&& (input2[0].value==""||input2[0].value=="0"))
{
input2[0].style.background='#E4E4E4';
input2[0].readOnly=true;
}
else if((input[0].value==""||input[0].value=="0")&& (input2[0].value!=""&&input2[0].value!="0"))
{
input[0].style.background='#E4E4E4';
input[0].readOnly=true;
}
else if ((input[0].value==""||input[0].value=="0") && (input2[0].value==""||input2[0].value=="0"))
{
input[0].style.background='white';
input2[0].style.background='white';
input2[0].readOnly=false;
input[0].readOnly=false;
}
UseHprice += parseInt(input[0].value);
UseGprice += parseInt(input2[0].value);
}
if (!re.test(document.getElementById(head+"txtUse_Cprice").value))
{
document.getElementById(head+"txtUse_Cprice").value=0;
}
var UseCprice=document.getElementById(head+"txtUse_Cprice").value;
var Allprice=parseInt(document.getElementById(head+"lblallprice2").innerHTML);
var HaveHprice=parseInt(document.getElementById(head+"lbHave_Hprice").innerHTML);
var HaveGprice=parseInt(document.getElementById(head+"lbHave_Gprice").innerHTML);
document.getElementById(head+"Text1").value=UseHprice;
document.getElementById(head+"Text2").value=UseGprice;
var Needprice=Allprice-UseHprice-UseGprice-UseCprice;
if(Needprice<0)
{
document .getElementById(head+"needprice").innerHTML="< src=pic/cuo_1.gif >充值卡支付過多!!";
}
else
{
document .getElementById(head+"needprice").innerHTML="您還需現金支付:<font color=red size=4pt>"+Needprice+"</font> 元";
}
// alert(input[0].value);
//alert(input[0].id);
//alert(input);
// if(input[0].id == obj.id){
//ele2 = tr.cells[1];
//ele2.
//}
}
</script>
ascx :
<asp:panel id="palDetail" BackColor="#fffff4" Width="500px" runat="server">
<P><FONT face="新細明體">您目前有國民卡點數:</FONT>
<asp:label id="lbHave_Gprice" runat="server" Width="40px" ForeColor="Red"></asp:label> 有紅利點數:
<asp:label id="lbHave_Hprice" runat="server" Width="40px" ForeColor="Red"></asp:label>
您目前有<FONT color="red">儲值卡</FONT>點數為:
<asp:label id="laHave_Cprice" runat="server" Width="40px" ForeColor="red"></asp:label>
</asp:panel><asp:panel id="palCart" Width="500px" runat="server">
<HR width="500" SIZE="2">
<TABLE cellSpacing="0" cellPadding="0" border="0">
<TR>
<TD vAlign="top" align="center" colSpan="2">國民卡和紅利點數每項只能二選一
<asp:datagrid id="dataGrid" runat="server" Width="500px" forecolor="Black" font-names="Verdana"
font-size="9pt" gridlines="None" borderwidth="1px" autogeneratecolumns="False" backcolor="White"
borderstyle="Solid" AllowPaging="True" CellSpacing="2" CellPadding="1">
<AlternatingItemStyle Height="20px" BackColor="White"></AlternatingItemStyle>
<ItemStyle HorizontalAlign="Center" VerticalAlign="Middle"></ItemStyle>
<HeaderStyle HorizontalAlign="Center" Height="25px" VerticalAlign="Middle" BackColor="#ece9d8"></HeaderStyle>
<Columns>
<asp:BoundColumn DataField="sId" ReadOnly="True" HeaderText="商品編號"></asp:BoundColumn>
<asp:TemplateColumn HeaderText="商品名稱">
<HeaderStyle ForeColor="#993333"></HeaderStyle>
<ItemTemplate>
<asp:hyperlink id="sName" runat="server" cssclass="text">
<a href='ProductShow.aspx?productid=<%# DataBinder.Eval(Container, "DataItem.sId") %>'>
<%# DataBinder.Eval(Container, "DataItem.sName") %>
</a>
</asp:hyperlink>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn Visible="False">
<HeaderTemplate>
<FONT face="新細明體" color="#993333">定價</FONT>
</HeaderTemplate>
<ItemTemplate>
<FONT face="新細明體">
<asp:Label id=lblspecprice runat="server" ForeColor=red Text='<%# DataBinder.Eval(Container, "DataItem.sPrice") %>'>
</asp:Label></FONT>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn>
<HeaderTemplate>
<FONT face="新細明體">
<asp:Label id="lblHeaderName" runat="server" Text="您的價格" ForeColor="#993333"></asp:Label></FONT>
</HeaderTemplate>
<ItemTemplate>
<asp:Label id="lalyourprice" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.specprice") %>' >
</asp:Label>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn Visible="False">
<HeaderTemplate>
<FONT face="新細明體" color="#993333">必須國民卡點數+紅卡利點數</FONT>
</HeaderTemplate>
<ItemTemplate>
<FONT face="新細明體">
<asp:Label id="Label1" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.GHprice") %>'>
</asp:Label>
</FONT>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="紅利點數">
<HeaderStyle ForeColor="#993333"></HeaderStyle>
<ItemTemplate>
<asp:textbox id="Hprice" runat="server" size="5px" Width="45px" BorderStyle="Groove" onblur="Checknull()"></asp:textbox>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="國民卡點數">
<HeaderStyle ForeColor="#993333"></HeaderStyle>
<ItemTemplate>
<asp:textbox id="Gprice" runat="server" size="5px" Width="45px" BorderStyle="Groove" onblur="Checknull()"></asp:textbox>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="數量">
<HeaderStyle ForeColor="#993333"></HeaderStyle>
<ItemTemplate>
<asp:textbox id="tbsNum" runat="server" BorderStyle="Groove" Text='<%# DataBinder.Eval(Container, "DataItem.sNum") %>' MaxLength="2" size="5px" Width="45px">
</asp:textbox>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn>
<HeaderTemplate>
<FONT face="新細明體">
<asp:Label id="Label2" runat="server" Text="單項小計" ForeColor="#993333"></asp:Label></FONT>
</HeaderTemplate>
<ItemTemplate>
<asp:Label id="lblunitAllprice" runat="server" ForeColor=red Text='<%# DataBinder.Eval(Container, "DataItem.unitAllprice") %>' >
</asp:Label>
</ItemTemplate>
</asp:TemplateColumn>
<asp:BoundColumn Visible="False" DataField="sName" ReadOnly="True"></asp:BoundColumn>
<asp:BoundColumn Visible="False" DataField="sNum" ReadOnly="True"></asp:BoundColumn>
<asp:ButtonColumn HeaderText="刪除" CommandName="delete" Text="刪除"></asp:ButtonColumn>
<asp:BoundColumn Visible="False" DataField="sPrice"></asp:BoundColumn>
</Columns>
<PagerStyle Mode="NumericPages"></PagerStyle>
</asp:datagrid><INPUT id="Text1" type="text" name="Text1" runat="server"><FONT face="新細明體">
<INPUT id="Text2" type="text" name="Text1" runat="server">
<TABLE cellSpacing="0" cellPadding="0" width="500" border="0">
<TR>
<TD width="100"><FONT style="FONT-WEIGHT: bold">統計:</FONT></TD>
<TD width="80"></TD>
<TD style="WIDTH: 231px" width="231"></TD>
<TD width="70"><FONT style="FONT-WEIGHT: bold">數量: </FONT>
<asp:Label id="lblAllNum" runat="server" Font-Size="14px"></asp:Label></TD>
<TD width="120"><FONT style="FONT-WEIGHT: bold">累計額:</FONT>
<asp:Label id="lblallprice2" runat="server" ForeColor="red" Font-Size="14px"></asp:Label></TD>
</TR>
</TABLE>
</FONT>
</TD>
</TR>
<TR>
<TD height="8"><FONT face="新細明體"></FONT></TD>
</TR>
<TR>
<TD height="8"></TD>
</TR>
<TR>
<TR>
<TD>購物車裏合計有
<asp:label id="lblNum" runat="server" ForeColor="Red"></asp:label> 件商品;<BR>
<asp:label id="txtNeedUse_GHprice" runat="server" ForeColor="Red" Visible="False"></asp:label>消費的金額:
<asp:label id="lblAllPrice" runat="server" ForeColor="Red" Font-Bold="True"></asp:label>
</TD>
</TR>
<TR>
<TD height="15"><!--此次購物使用國民卡點數:
<asp:textbox id=tbUse_Gprice runat="server" Width="56px" Height="18px" BorderStyle="Groove"></asp:textbox>
<asp:regularexpressionvalidator id=Regularexpressionvalidator2 runat="server" ValidationExpression="[0-9]+/.?[0-9]*" ErrorMessage="*請輸入數字" ControlToValidate="tbUse_Gprice" Display="Dynamic"></asp:regularexpressionvalidator>使用紅利點數:
<asp:textbox id=tbUse_Hprice runat="server" Width="56px" Height="18px" BorderStyle="Groove"></asp:textbox>
<asp:regularexpressionvalidator id=Regularexpressionvalidator1 runat="server" ValidationExpression="[0-9]+/.?[0-9]*" ErrorMessage="*請輸入數字" ControlToValidate="tbUse_Hprice" Display="Dynamic"></asp:regularexpressionvalidator>-->
使用<FONT color="red">儲值卡</FONT>
<asp:textbox id="txtUse_Cprice" onblur="Checknull()" runat="server" Height="18px" BorderStyle="Groove" width="45px"></asp:textbox>
<asp:regularexpressionvalidator id="Regularexpressionvalidator4" runat="server" ValidationExpression="[0-9]+/.?[0-9]*"
ErrorMessage="*請輸入數字" ControlToValidate="txtUse_Cprice" Display="Dynamic"></asp:regularexpressionvalidator>點
</TD>
</TR>
<TR>
<TD style="HEIGHT: 16px"><FONT face="新細明體">
<DIV id="needprice" style="BORDER-RIGHT: #ffbcff 1px solid; Font-Size:13px; BORDER-TOP: #ffbcff 1px solid; BORDER-LEFT: #ffbcff 1px solid; BORDER-BOTTOM: #ffbcff 1px solid; BACKGROUND-COLOR: #fff5f8" runat="server" ms_positioning="FlowLayout"></DIV>
</FONT>
</TD>
</TR>
<TR>
<TD height="10"><FONT face="新細明體"></FONT></TD>
</TR>
<TR>
<TD vAlign="top">
<TABLE id="Table1" cellSpacing="0" cellPadding="0" width="500" border="0">
<TR>
<TD style="WIDTH: 469px" align="right">
<asp:imagebutton id="btnUpdateNum" runat="server" ImageUrl="pic/gxsl_ok.gif"></asp:imagebutton>
<asp:imagebutton id="btnGoOn" runat="server" ImageUrl="pic/jxgw_ok.gif"></asp:imagebutton></TD>
<TD style="WIDTH: 252px">
<P>
<asp:ImageButton id="IBtnNext" runat="server" ImageUrl="pic/xyb_ok.gif"></asp:ImageButton></P>
</TD>
<TD>
<P> </P>
</TD>
</TR>
</TABLE>
</TD>
</TR>
<TR>
<TD class="new"><FONT face="新細明體"></FONT></TD>
</TR>
</TABLE>
<P></P>
</asp:panel><asp:panel id="palerror" Width="500px" runat="server"><FONT face="新細明體" size="3"> <IMG src="pic/warm.gif" align="absBottom">您的購物車中沒有商品
</FONT>
</asp:panel>