Hejsan!JavaScript i form?
har en shop som jag hittat, jag skulle vilja fixa till den lite.
det som detta javascript gör skulle jag vilja få in i en form (textarea) eller som vanlig html text så att jag kan få med det i oder mailet.
jag har testat med dessa 2 olika varianter att skriva ut det på sidan men inget av dessa 2 har jag fått att funka.
det är det som '+theitem+' skriver ut som jag vill få med mig till en form
<code><script LANGUAGE="JavaScript">
showItems();
</script></code>
<code><%
Response.Write ("<HTML><HEAD><SCRIPT> ")
Response.Write ("javascript:showItems();")
Response.Write ("</SCRIPT></HEAD></HTML>")
%></code>
<code><script LANGUAGE="JavaScript">
function alterError(value) {
if (value<=0.99) {
newDollar = '0';
} else {
newDollar = parseInt(value);
}
newCent = parseInt((value+.0008 - newDollar)* 100);
if (eval(newCent) <= 9) newCent='0'+newCent;
newString = newDollar + '.' + newCent;
return (newString);
}
// showItems in orderform
function showItems() {
index = document.cookie.indexOf("ShoppingBasket");
countbegin = (document.cookie.indexOf("=", index) + 1);
countend = document.cookie.indexOf(";", index);
if (countend == -1) {
countend = document.cookie.length;
}
fulllist = document.cookie.substring(countbegin, countend);
subtotal = 0;
subweight = 0;
document.writeln('<table cellpadding="2" cellspacing="1" border="0">');
document.writeln('<TR><TD BGCOLOR="#B3B3B3"><font size="-2" face="Verdana, Arial, Helvetica, sans-serif"><b><%=txt_qty%></b></FONT></TD><TD BGCOLOR="#B3B3B3"><font size="-2" face="Verdana, Arial, Helvetica, sans-serif"><b><%=txt_code_no%></b></FONT></TD><TD BGCOLOR="#B3B3B3"><font size="-2" face="Verdana, Arial, Helvetica, sans-serif"><b><%=txt_item%></b></FONT></TD><TD BGCOLOR="#B3B3B3"><font size="-2" face="Verdana, Arial, Helvetica, sans-serif"><b><%=txt_price%> <%=txt_currency%></b></FONT></TD><td BGCOLOR="#B3B3B3"><font size="-2" face="Verdana, Arial, Helvetica, sans-serif"><b><%=txt_total%></b></FONT></td></TR>');
itemlist = 0;
for (var i = 0; i <= fulllist.length; i++) {
if (fulllist.substring(i,i+1) == '[') {
thisitem = 1;
itemstart = i+1;
} else if (fulllist.substring(i,i+1) == ']') {
itemend = i;
thequantity = fulllist.substring(itemstart, itemend);
itemtotal = 0;
itemtotal = (eval(theprice*thequantity));
temptotal = itemtotal * 100;
subtotal = subtotal + itemtotal;
weighttotal = 0;
weighttotal = (eval(theweight*thequantity));
subweight = subweight + weighttotal;
itemlist=itemlist+1;
document.write('<tr><td align=middle BGCOLOR="#D9D9D9"><font size="-2" face="Verdana, Arial, Helvetica, sans-serif">'+thequantity+'</FONT></td>');
document.writeln('<td BGCOLOR="#D9D9D9"><font size="-2" face="Verdana, Arial, Helvetica, sans-serif">'+thenumber+'</FONT></td><td align=left BGCOLOR="#D9D9D9"><font size="-2" face="Verdana, Arial, Helvetica, sans-serif">'+theitem+'</FONT></td><td align=right BGCOLOR="#D9D9D9"><font size="-2" face="Verdana, Arial, Helvetica, sans-serif">'+theprice+'</FONT></td><td align=right BGCOLOR="#D9D9D9"><font size="-2" face="Verdana, Arial, Helvetica, sans-serif">'+alterError(itemtotal)+'</FONT></td></tr>');
} else if (fulllist.substring(i,i+1) == '|') {
if (thisitem==1) theitem = fulllist.substring(itemstart, i);
if (thisitem==2) theprice = fulllist.substring(itemstart, i);
if (thisitem==3) thenumber = fulllist.substring(itemstart, i);
if (thisitem==4) theweight = fulllist.substring(itemstart, i);
thisitem++;
itemstart=i+1;
}
}
totprice = (Math.round(subtotal*100)/100);
shipping = subweight+<%=add_freight%>;
totalcost = (totprice+shipping);
tax = (Math.round(totalcost*<%=add_tax%>)/100);
document.writeln('<tr><td align=right BGCOLOR="#B3B3B3" colspan=4><font size="-2" face="Verdana, Arial, Helvetica, sans-serif"><b><%=txt_product_total%></b></FONT></td><td align=right BGCOLOR="#D9D9D9"><font size="-2" face="Verdana, Arial, Helvetica, sans-serif">'+alterError(totprice)+'</FONT></td></tr>');
document.writeln('<tr><td align=right BGCOLOR="#B3B3B3" colspan=4><font size="-2" face="Verdana, Arial, Helvetica, sans-serif"><b><%=txt_shipping%></b></FONT></td><td align=right BGCOLOR="#D9D9D9"><font size="-2" face="Verdana, Arial, Helvetica, sans-serif">'+alterError(shipping)+'</FONT></td></tr>');
<%if add_tax > "0" then%>
document.writeln('<tr><td align=right BGCOLOR="#B3B3B3" colspan=4><font size="-2" face="Verdana, Arial, Helvetica, sans-serif"><b><%=txt_tax%></b></FONT></td><td align=right BGCOLOR="#D9D9D9"><font size="-2" face="Verdana, Arial, Helvetica, sans-serif">'+alterError(tax)+'</FONT></td></tr>');
<% end if %>
document.writeln('<tr><td align=right BGCOLOR="#B3B3B3" colspan=4><font size="-2" face="Verdana, Arial, Helvetica, sans-serif"><b><%=txt_grand_total%> <%=txt_currency%></b></FONT></td><td align=right BGCOLOR="#D9D9D9"><font size="-2" face="Verdana, Arial, Helvetica, sans-serif">'+alterError(totalcost+tax)+'</FONT></td></tr>');
document.writeln('<INPUT TYPE="hidden" NAME="total" VALUE="'+alterError(totalcost+tax)+'" SIZE="40">');
document.writeln('</TABLE>');
}
</script></code>
/Tommy