В head:
Код:
<script language="JavaScript">
<!--
function createArray(size) {
for (var i=0; i < size; i++) {
this[i] = null }
return this
}
function Product(descrip, money) {
this.description = descrip;
this.price = money;
}
function Category(name) {
this.title = name;
this.product = new createArray(1);
this.product[0] = new Product("Пожалуйста, выберите", 0.00);
}
var category = new createArray(1);
// STEP NUMBER ONE
// enter the color for rows of the table
// (either javascript name or hex code)
color1 = "tan";
color2 = "khaki";
category[1] = new Category("Сайт");
category[1].product[1] = new Product("Сайт персональный", 2550);
category[1].product[2] = new Product("Пылесос", 30);
category[2] = new Category("Дополнительные услуги");
category[2].product[1] = new Product("Шампанское", 15.50);
category[2].product[2] = new Product("Коньяк", 39.95);
// ***** NO NEED TO CHANGE ANY CODE AFTER THIS COMMENT ***
function SetLengths() {
var k=1;
while(category[k] != null)
k++
category.length = k;
for (i=1; i<category.length; i++) {
var j=1;
while (category[i].product[j] != null)
j++;
category[i].product.length = j;
}
}
SetLengths();
function writeTableRow(i) {
document.write('<tr bgcolor="' + ((i%2 == 0) ? color1 : color2) + '">');
document.write('<td>' + category[i].title.toUpperCase() + ':<br>'
+ '<select size="1" name="menu' + i + '" onChange="update(' + i + ')">');
len = category[i].product.length;
for (j=0; j<len; j++) {
if (j != 0)
document.write('<option>' + category[i].product[j].description
+ ' - $' + fix(category[i].product[j].price) + '</option>');
else
document.write('<option selected value=" ">Пожалуйста, выберите</option>');
}
document.write('</select></td><td valign=bottom>'
+ '<input type="text" value="0.00" name="price' + i + '" '
+ 'size=12 maxlength=12 onFocus="document.form1.price' + i + '.blur()">'
+ '</td></tr>');
}
function writeTable() {
document.write('<table cellspacing=5 cellpadding=10 border=0>');
for (i=1; i<category.length; i++)
writeTableRow(i);
document.write('<tr bgcolor="' + ((category.length%2==0) ? color1 : color2)
+ '"><td align=right>ВСЕГО НА СУММУ: </td><td><input type="text" '
+ 'name="total" size=12 maxlength=12 value="0.00"></td></tr></table>');
}
function update(num) {
eval('selected = document.form1.menu' + num + '.selectedIndex;');
cost = fix(category[num].product[selected].price);
eval('document.form1.price' + num + '.value = cost;');
var grand_total = 0;
for (i=1; i<category.length; i++)
eval('grand_total += parseFloat(document.form1.price' + i + '.value);');
document.form1.total.value = fix(grand_total);
}
function fix(num) {
string = "" + num;
if (string.indexOf('.') == -1)
return string + '.00';
seperation = string.length - string.indexOf('.');
if (seperation > 3)
return string.substring(0,string.length-seperation+3);
else if (seperation == 2)
return string + '0';
return string;
}
function validate_form() {
validity = true;
if (document.form1.email.value == "") {
if (confirm("Вы будете вводить email адрес?"))
valid = false;
else
document.form1.email.value = 'email адрес не введен';
}
if (document.form1.bill.value == "") {
alert('Введите адрес для отправки счета!');
validity = false;
} else if (document.form1.mail.value == "") {
if (!confirm("Отправлять заказ по томуже адресу, что и счета?"))
validity = false;
else
document.form1.mail.value = 'тот же, что и адрес для счета';
}
if (validity){
alert("Спасибо за заказ!");
return true;
}
else{
return false;
}
}
// -->
</script>
<!-- форма покупки javaS -->
В body:
Код:
<center>
<table border=2 bgcolor="white" align=center>
<tr><td align=center>
<font face="Arial, Helvetica, Geneva" size="+2" color="black"><b>Ваш заказ</b></font>
<font size="3" color="#000000">
<br><br>
<form name="form1" method="post" action="cube-web@yandex.ru ?SUBJECT=Заказ онлайн" enctype="text/plain" onsubmit="return validate_form()">
<script language="JavaScript">
writeTable();
</script>
<table cellspacing=0 cellpadding=5 bgcolor="tan">
<tr><td align=center>
Ф.И.О: <input type="text" name="shopper_name" size=44><br>
*Email: <input type="text" size=44 name="email"><br>
Телефон: <input type="text" size="20" name="phone"><br>
*Способ оплаты: <input type="text" size="20" name="credit_card_number">
</table><br>
<input type="submit" name="submit" value="Отправить заказ"> 
<input type="reset" value="Сброс"><br>
</form>
</font>
</td></tr></table>
</center>
Не получается реализовать, чтобы, например при выборе того или иного товара - вылезало окошко\текст с описанием ЧТО ЭТО такое собственно.
Может кто знает как реализовать? Или посоветуйте готовый скрипт который подредактировав минимально, предусматривается вышеописанная функция.