>Форум Mozilla Россия http://forum.mozilla-russia.org/index.php >Разработка http://forum.mozilla-russia.org/viewforum.php?id=18 >Не работает Java Script http://forum.mozilla-russia.org/viewtopic.php?id=42871 |
grmaster > 23-01-2010 11:48:15 |
Всем привет. Похожая проблема возникла. В IE, Opera скрипт работает, в Firefox нет. Чувствую, что совет "Как же надоело объяснять, что элементы с id НЕ становятся автоматически javascript-объектами. Используйте document.getElementById" рабочий. Однако не совсем пока понимаю что в коде и где поменять надо. Вставлял скрипт в Joomla при отключенном виз.редакторе. Код прилагаю. Помогите советом, пож-ста. Сейчас в джумле прописано так: Выделить код Код:<style type="text/css"> <!-- .style3 {color: #0099CC} --> </style> <table align="center" class="bgc2 w100p mb16" cellspacing="1" cellpadding="1" width="100%"> <script type="text/javascript"> var maxweight = {"Armenia": {"priority": 44, "express": 44},"Azerbaijan": {"priority": 70, "express": 70},"Belarus": {"priority": 66, "express": 44},"Estonia": {"priority": 70, "express": 66},"France": {"priority": 66, "express": 44},"Germany": {"priority": 66, "express": 44},"Georgia": {"priority": 44, "express": 66},"Israel": {"priority": 44, "express": 44},"Kazakhstan": {"priority": 44, "express": 66},"Kyrgyzstan": {"priority": 44, "express": 66},"Latvia": {"priority": 70, "express": 66},"Lithuania": {"priority": 70, "express": 70},"Moldova": {"priority": 70, "express": 70},"Poland": {"priority": 66, "express": 44},"Russia": {"priority": 44, "express": 66},"Tajikistan": {"priority": 66, "express": 66},"Turkmenistan": {"priority": 44, "express": 66},"Ukraine": {"priority": 66, "express": 44},"Uzbekistan": {"priority": 70, "express": 66}}; function ShippingMethod() { sel = pounds.selectedIndex; pounds.innerHTML = null; for (i = 1; i <= maxweight[shipping_country.value][shipping_method.value]; i ++) pounds.options[i - 1] = new Option(i + " (≈" + (Math.round(i * 45.359237) / 100) + " кг)", i); if (sel >= 0 && sel < pounds.options.length) pounds.selectedIndex = sel; } function ClearTotal() { total.innerHTML = ""; our_fee.innerHTML = ""; shipping_cost.innerHTML = ""; } var calc_base = {0: {"priority": 19.75, "express": 27.25}, 1: {"priority": 20.75, "express": 27.25}, 2: {"priority": 18.75, "express": 28.50}}; var calc_k = {0: {"priority": [{"pound": 99, "k": 3.75}], "express": [{"pound": 5, "k": 4.25}, {"pound": 10, "k": 3.75}, {"pound": 99, "k": 4.25}]}, 1: {"priority": [{"pound": 5, "k": 4.25}, {"pound": 99, "k": 5.25}], "express": [{"pound": 5, "k": 4.25}, {"pound": 10, "k": 5.25}, {"pound": 40, "k": 5.75}, {"pound": 99, "k": 5.25}]}, 2: {"priority": [{"pound": 10, "k": 4.25}, {"pound": 99, "k": 4.75}], "express": [{"pound": 10, "k": 5}, {"pound": 99, "k": 5.75}]}} var calc_country = {"Armenia": 0, "Azerbaijan": 0, "Belarus": 0, "Estonia": 0, "France": 0, "Germany": 0, "Georgia": 0, "Israel": 2, "Kazakhstan": 1, "Kyrgyzstan": 1, "Latvia": 0, "Lithuania": 0, "Moldova": 0, "Poland": 0, "Russia": 0, "Tajikistan": 1, "Turkmenistan": 1, "Ukraine": 0, "Uzbekistan": 1} function Calc2() { if (zakaz_cost.value * 1 + zakaz_shipping.value * 1 == 0) { our_fee.innerHTML = "$0"; shipping_cost.innerHTML = "$0"; total.innerHTML = "$0*"; } else { fee = Math.round((zakaz_cost.value * 1) * 10) / 100; fee = fee > 10 ? fee : 10; cost = calc_base[calc_country[shipping_country.value]][shipping_method.value]; p = 0; for (i = 0; i < calc_k[calc_country[shipping_country.value]][shipping_method.value].length; i++) { if (pounds.value <= calc_k[calc_country[shipping_country.value]][shipping_method.value][i]["pound"]) { cost += (pounds.value - p) * calc_k[calc_country[shipping_country.value]][shipping_method.value][i]["k"]; break; } else { cost += (calc_k[calc_country[shipping_country.value]][shipping_method.value][i]["pound"] - p) * calc_k[calc_country[shipping_country.value]][shipping_method.value][i]["k"]; p = calc_k[calc_country[shipping_country.value]][shipping_method.value][i]["pound"]; } } // shipping_cost.innerHTML = "$" + cost * 1; if (shipping_method.value == "priority") { if (insurance.value == 50) cost += 2.45; else if (insurance.value > 50) cost += 2.4 + insurance.value / 100 * 0.95; } else { if (insurance.value > 200) cost += 2.1; else if (insurance.value > 100) cost += 0.75; } our_fee.innerHTML = "$" + fee; shipping_cost.innerHTML = "$" + cost * 1; total.innerHTML = "$" + (zakaz_cost.value * 1 + zakaz_shipping.value * 1 + fee * 1 + cost * 1) + "*"; } } </script> <table width="100%" style="border: 1px solid #cdeeff; background:url(images/stories/table_bg.jpg) repeat-x;" align="center" cellpadding="1" cellspacing="5"> <tr class="bgc1 ac h24"> <th class="bgc3" width="615"> <div align="right" class="style3">Стоимость товаров: </div></th> <th width="738"><div align="left"> <input type="text" class="inputbox" id="zakaz_cost" value="0" size="26" onKeyUp="ClearTotal()" onblur="if(this.value==\'\') this.value=\''.$text.'\';" onfocus="if(this.value==\''.$text.'\') this.value=\'\';"> $</div></th> </tr> <tr class="bgc1 ac h24"> <th> <div align="right" class="style3">Доставка по США: </div></th> <th><div align="left"> <input type="text" class="inputbox" id="zakaz_shipping" value="0" size="26" onKeyUp="ClearTotal()" onblur="if(this.value==\'\') this.value=\''.$text.'\';" onfocus="if(this.value==\''.$text.'\') this.value=\'\';"> $</div></th> </tr> <tr> <th> <div align="right" class="style3">Тип доставки: </div> </th> <th><div align="left"> <select name="shipping_method" class="inputbox" id="shipping_method" style="width:200px;" onChange="ShippingMethod(); ClearTotal()"> <option>Выберите тип доставки</option> <option value="express">EMS</option> <option value="priority">Priority Mail</option> </select> </div></th> </tr> <tr class="bgc1 ac h24"> <th> <div align="right" class="style3">Страна доставки: </div></th> <th><div align="left"> <select class="inputbox" style="width:200px;" name="shipping_country" id="shipping_country" onChange="ShippingMethod(); ClearTotal()"> <option>Выберите страну доставки</option> <option value="Armenia">Армения</option> <option value="Azerbaijan">Азербайджан</option> <option value="Belarus">Беларусь</option> <option value="Estonia">Эстония</option> <option value="France">Франция</option> <option value="Germany">Германия</option> <option value="Georgia">Грузия</option> <option value="Israel">Израиль</option> <option value="Kazakhstan">Казахстан</option> <option value="Kyrgyzstan">Киргизстан</option> <option value="Latvia">Латвия</option> <option value="Lithuania">Литва</option> <option value="Moldova">Молдова</option> <option value="Poland">Польша</option> <option value="Russia" selected>Россия</option> <option value="Tajikistan">Таджикистан</option> <option value="Turkmenistan">Туркменистан</option> <option value="Ukraine">Украина</option> <option value="Uzbekistan">Узбекистан</option> </select> </div></th> </tr> <tr class="bgc1 ac h24"> <th> <div align="right" class="style3">Вес товара: </div></th> <th><div align="left"> <select class="inputbox" style="width:200px;" id="pounds" onChange="ShippingMethod(); ClearTotal()"> <option>Выберите вес товара</option> </select> </td>кг</div></th> </tr> <tr class="bgc1 ac h24"> <th class="bgc3"> <div align="right" class="style3">Страхование: </div></th> <th><div align="left"> <select class="inputbox" style="width:200px;" id="insurance" onChange="ClearTotal()"> <option>Выберите страхование</option> <option value="0">$0</option> <option value="50">$1-$50</option> <option value="100">$51-$100</option> <option value="200">$101-$200</option> <option value="300">$201-$300</option> <option value="400">$301-$400</option> <option value="500">$401-$500</option> </select> </td> $</div></th> </tr> <tr class="bgc1 ac h24"> <td colspan="2"><div align="center" class="style2"> <div align="center"> <input class="button" style="margin: 8px" type="submit" value="Расчет затрат" onClick="Calc2()"> </div> </div></td> </tr> <tr> <th> <div align="right" class="style3">Пересылка:</div></th> <td><font color="#1b88bd" size="3"><span id="shipping_cost"></span></font></td> </tr> <tr> <th> <div align="right" class="style3">Наша комиссия:</div></th> <td><font color="#1b88bd" size="3"><span id="our_fee"></span></font></td> </tr> <tr> <td colspan="2"><div align="left"><span class="style1"><span class="style3"><span class="style3"></span></span></span></div></td> </tr> <tr> <th> <div align="right" class="style3">Ваши затраты:</div></th> <th><div align="left"><font color="green" size="5"><span id="total"></span></font></div></th> </tr> <tr class="bgc1 ac h32"> <td align="center" colspan="2"> <font size="-2">* Конечная стоимость заказа может отличаться от рассчитанной. Подробнее о ценах, а также о наших дополнительных услугах Вы можете узнать на странице <a href="index.php?option=com_content&view=article&id=81&Itemid=95">Наши тарифы</a></font> </td> </tr> </table> |
Al_H > 24-01-2010 01:39:11 |
Вот видите, Вы сами все знаете. Ищите, где у Вас в тэгах id="..." и где в JavaScript используются эти id, и затем заменяйте их на корректную конструкцию. |
Infocatcher > 24-01-2010 02:03:08 |
Проще к консоль ошибок заглянуть. |
grmaster > 26-01-2010 16:10:17 |
Всем привет. Поменял код так: zakaz_cost на document.getElementById('zakaz_cost') (и так заменил все id). Вставил в Joomla. Теперь в Firefox частично заработало, но при весе больше 2.27кг не показывает расчитанную сумму Если можете, посмотрите правильно ли заменил id на document.getElementById. Код: Выделить код Код:<style type="text/css"> <!-- .style3 {color: #0099CC} --> </style> <table align="center" class="bgc2 w100p mb16" cellspacing="1" cellpadding="1" width="100%"> <script type="text/javascript"> var maxweight = {"Armenia": {"priority": 44, "express": 44},"Azerbaijan": {"priority": 70, "express": 70},"Belarus": {"priority": 66, "express": 44},"Estonia": {"priority": 70, "express": 66},"France": {"priority": 66, "express": 44},"Germany": {"priority": 66, "express": 44},"Georgia": {"priority": 44, "express": 66},"Israel": {"priority": 44, "express": 44},"Kazakhstan": {"priority": 44, "express": 66},"Kyrgyzstan": {"priority": 44, "express": 66},"Latvia": {"priority": 70, "express": 66},"Lithuania": {"priority": 70, "express": 70},"Moldova": {"priority": 70, "express": 70},"Poland": {"priority": 66, "express": 44},"Russia": {"priority": 44, "express": 66},"Tajikistan": {"priority": 66, "express": 66},"Turkmenistan": {"priority": 44, "express": 66},"Ukraine": {"priority": 66, "express": 44},"Uzbekistan": {"priority": 70, "express": 66}}; function ShippingMethod() { sel = document.getElementById('pounds').selectedIndex; document.getElementById('pounds').innerHTML = null; for (i = 1; i <= maxweight[document.getElementById('shipping_country').value][document.getElementById('shipping_method').value]; i ++) document.getElementById('pounds').options[i - 1] = new Option(i + " (≈" + (Math.round(i * 45.359237) / 100) + " кг)", i); if (sel >= 0 && sel < document.getElementById('pounds').options.length) document.getElementById('pounds').selectedIndex = sel; } function ClearTotal() { document.getElementById('total').innerHTML = ""; document.getElementById('our_fee').innerHTML = ""; document.getElementById('shipping_cost').innerHTML = ""; } var calc_base = {0: {"priority": 19.75, "express": 27.25}, 1: {"priority": 20.75, "express": 27.25}, 2: {"priority": 18.75, "express": 28.50}}; var calc_k = {0: {"priority": [{"pound": 99, "k": 3.75}], "express": [{"pound": 5, "k": 4.25}, {"pound": 10, "k": 3.75}, {"pound": 99, "k": 4.25}]}, 1: {"priority": [{"pound": 5, "k": 4.25}, {"pound": 99, "k": 5.25}], "express": [{"pound": 5, "k": 4.25}, {"pound": 10, "k": 5.25}, {"pound": 40, "k": 5.75}, {"pound": 99, "k": 5.25}]}, 2: {"priority": [{"pound": 10, "k": 4.25}, {"pound": 99, "k": 4.75}], "express": [{"pound": 10, "k": 5}, {"pound": 99, "k": 5.75}]}} var calc_country = {"Armenia": 0, "Azerbaijan": 0, "Belarus": 0, "Estonia": 0, "France": 0, "Germany": 0, "Georgia": 0, "Israel": 2, "Kazakhstan": 1, "Kyrgyzstan": 1, "Latvia": 0, "Lithuania": 0, "Moldova": 0, "Poland": 0, "Russia": 0, "Tajikistan": 1, "Turkmenistan": 1, "Ukraine": 0, "Uzbekistan": 1} function Calc2() { if (document.getElementById('zakaz_cost').value * 1 + document.getElementById('zakaz_shipping').value * 1 == 0) { document.getElementById('our_fee').innerHTML = "$0"; document.getElementById('shipping_cost').innerHTML = "$0"; document.getElementById('total').innerHTML = "$0*"; } else { fee = Math.round((document.getElementById('zakaz_cost').value * 1) * 10) / 100; fee = fee > 10 ? fee : 10; cost = calc_base[calc_country[document.getElementById('shipping_country').value]][document.getElementById('shipping_method').value]; p = 0; for (i = 0; i < calc_k[calc_country[document.getElementById('shipping_country').value]][document.getElementById('shipping_method').value].length; i++) { if (document.getElementById('pounds').value <= calc_k[calc_country[document.getElementById('shipping_country').value]][document.getElementById('shipping_method').value][i]["pound"]) { cost += (document.getElementById('pounds').value - p) * calc_k[calc_country[document.getElementById('shipping_country').value]][document.getElementById('shipping_method').value][i]["k"]; break; } else { cost += (calc_k[calc_country[document.getElementById('shipping_country').value]][document.getElementById('shipping_method').value][i]["pound"] - p) * calc_k[calc_country[shipping_country.value]][document.getElementById('shipping_method').value][i]["k"]; p = calc_k[calc_country[document.getElementById('shipping_country').value]][document.getElementById('shipping_method').value][i]["pound"]; } } // document.getElementById('shipping_cost').innerHTML = "$" + cost * 1; if (document.getElementById('shipping_method').value == "priority") { if (document.getElementById('insurance').value == 50) cost += 2.45; else if (document.getElementById('insurance').value > 50) cost += 2.4 + document.getElementById('insurance').value / 100 * 0.95; } else { if (document.getElementById('insurance').value > 200) cost += 2.1; else if (document.getElementById('insurance').value > 100) cost += 0.75; } document.getElementById('our_fee').innerHTML = "$" + fee; document.getElementById('shipping_cost').innerHTML = "$" + cost * 1; document.getElementById('total').innerHTML = "$" + (document.getElementById('zakaz_cost').value * 1 + document.getElementById('zakaz_shipping').value * 1 + fee * 1 + cost * 1) + "*"; } } </script> <table width="100%" style="border: 1px solid #cdeeff; background:url(images/stories/table_bg.jpg) repeat-x;" align="center" cellpadding="1" cellspacing="5"> <tr class="bgc1 ac h24"> <th class="bgc3" width="615"> <div align="right" class="style3">Стоимость товаров: </div></th> <th width="738"><div align="left"> <input type="text" class="inputbox" id="zakaz_cost" value="0" size="26" onKeyUp="ClearTotal()" onblur="if(this.value==\'\') this.value=\''.$text.'\';" onfocus="if(this.value==\''.$text.'\') this.value=\'\';"> $</div></th> </tr> <tr class="bgc1 ac h24"> <th> <div align="right" class="style3">Доставка по США: </div></th> <th><div align="left"> <input type="text" class="inputbox" id="zakaz_shipping" value="0" size="26" onKeyUp="ClearTotal()" onblur="if(this.value==\'\') this.value=\''.$text.'\';" onfocus="if(this.value==\''.$text.'\') this.value=\'\';"> $</div></th> </tr> <tr> <th> <div align="right" class="style3">Тип доставки: </div> </th> <th><div align="left"> <select name="shipping_method" class="inputbox" id="shipping_method" style="width:200px;" onChange="ShippingMethod(); ClearTotal()"> <option>Выберите тип доставки</option> <option value="express">EMS</option> <option value="priority">Priority Mail</option> </select> </div></th> </tr> <tr class="bgc1 ac h24"> <th> <div align="right" class="style3">Страна доставки: </div></th> <th><div align="left"> <select class="inputbox" style="width:200px;" name="shipping_country" id="shipping_country" onChange="ShippingMethod(); ClearTotal()"> <option>Выберите страну доставки</option> <option value="Armenia">Армения</option> <option value="Azerbaijan">Азербайджан</option> <option value="Belarus">Беларусь</option> <option value="Estonia">Эстония</option> <option value="France">Франция</option> <option value="Germany">Германия</option> <option value="Georgia">Грузия</option> <option value="Israel">Израиль</option> <option value="Kazakhstan">Казахстан</option> <option value="Kyrgyzstan">Киргизстан</option> <option value="Latvia">Латвия</option> <option value="Lithuania">Литва</option> <option value="Moldova">Молдова</option> <option value="Poland">Польша</option> <option value="Russia" selected>Россия</option> <option value="Tajikistan">Таджикистан</option> <option value="Turkmenistan">Туркменистан</option> <option value="Ukraine">Украина</option> <option value="Uzbekistan">Узбекистан</option> </select> </div></th> </tr> <tr class="bgc1 ac h24"> <th> <div align="right" class="style3">Вес товара: </div></th> <th><div align="left"> <select class="inputbox" style="width:200px;" id="pounds" onChange="ShippingMethod(); ClearTotal()"> <option>Выберите вес товара</option> </select> </td>кг</div></th> </tr> <tr class="bgc1 ac h24"> <th class="bgc3"> <div align="right" class="style3">Страхование: </div></th> <th><div align="left"> <select class="inputbox" style="width:200px;" id="insurance" onChange="ClearTotal()"> <option>Выберите страхование</option> <option value="0">$0</option> <option value="50">$1-$50</option> <option value="100">$51-$100</option> <option value="200">$101-$200</option> <option value="300">$201-$300</option> <option value="400">$301-$400</option> <option value="500">$401-$500</option> </select> </td> $</div></th> </tr> <tr class="bgc1 ac h24"> <td colspan="2"><div align="center" class="style2"> <div align="center"> <input class="button" style="margin: 8px" type="submit" value="Расчет затрат" onClick="Calc2()"> </div> </div></td> </tr> <tr> <th> <div align="right" class="style3">Пересылка:</div></th> <td><font color="#1b88bd" size="3"><span id="shipping_cost"></span></font></td> </tr> <tr> <th> <div align="right" class="style3">Наша комиссия:</div></th> <td><font color="#1b88bd" size="3"><span id="our_fee"></span></font></td> </tr> <tr> <td colspan="2"><div align="left"><span class="style1"><span class="style3"><span class="style3"></span></span></span></div></td> </tr> <tr> <th> <div align="right" class="style3">Ваши затраты:</div></th> <th><div align="left"><font color="green" size="5"><span id="total"></span></font></div></th> </tr> <tr class="bgc1 ac h32"> <td align="center" colspan="2"> <font size="-2">* Конечная стоимость заказа может отличаться от рассчитанной. Подробнее о ценах, а также о наших дополнительных услугах Вы можете узнать на странице <a href="index.php?option=com_content&view=article&id=81&Itemid=95">Наши тарифы</a></font> </td> </tr> </table> |