Jump to content
  • 0

javascript в посте


irene
 Share

Question

Здравствуйте! Помогите пожалуйста разобраться, почему javascript размещенный в посте перестал работать после обновления WordPress (сейчас - 3.5.1). Я не слишком хорошо знаю javascript, но написанный скрипт все же работал и сейчас правильно работает на простой html странице. Вот код:


<script type="text/javascript">
var lea_product = new Array();
lea_product[1] = "LEA AH1500";
lea_product[2] = "LEA AH2000";
lea_product[3] = "LEA AH1500 (x2)"
lea_product[4] = "LEA AH1500 + LEA AH2000";
lea_product[5] = "LEA AH2000 (x2)";
lea_product[6] = "LEA AH2000 (x2) + LEA AH1500";
lea_product[7] = "LEA AH2000 (x3)";
lea_product[8] = "LEA AH2000 (x4)";

var lea_watt = new Array();
lea_watt[1] = 1500;
lea_watt[2] = 2000;
lea_watt[3] = 3000;
lea_watt[4] = 3500;
lea_watt[5] = 4000;
lea_watt[6] = 5500;
lea_watt[7] = 6000;
lea_watt[8] = 8000;

var lea_cost = new Array();
lea_cost[1] = 3500;
lea_cost[2] = 3750;
lea_cost[3] = 7000;
lea_cost[4] = 7250;
lea_cost[5] = 7500;
lea_cost[6] = 11000;
lea_cost[7] = 11250;
lea_cost[8] = 15000;

var lea_size = new Array();
lea_size[1] = 15;
lea_size[2] = 20;
lea_size[3] = 30;
lea_size[4] = 35;
lea_size[5] = 40;
lea_size[6] = 55;
lea_size[7] = 60;
lea_size[8] = 80;

var flora_product = new Array();
flora_product[1] = "FLORA TW500";
flora_product[2] = "FLORA TW600";
flora_product[3] = "FLORA TW750";
flora_product[4] = "FLORA TW900";
flora_product[5] = "FLORA TW1200";
var flora_watt = new Array;
flora_watt[1] = 500;
flora_watt[2] = 600;
flora_watt[3] = 750;
flora_watt[4] = 900;
flora_watt[5] = 1200;

var flora_cost = new Array();
flora_cost[1] = 2150;
flora_cost[2] = 2220;
flora_cost[3] = 2300;
flora_cost[4] = 2500;
flora_cost[5] = 2500;

var flora_size = new Array();
flora_size[1] = 5;
flora_size[2] = 6;
flora_size[3] = 7.5;
flora_size[4] = 9;
flora_size[5] = 80;

var numericExpression = /^[0-9\.]+$/;
var n_lines = 10;
var maxroomsize = 80;

function price() {
var bill = 0;
var watt = document.getElementById('watts_total').value;
var kwh_price = document.getElementById('kwh_price').value;
if (kwh_price == "") kwh_price = 0;
if(kwh_price.match(numericExpression)) {
bill = (watt/1000 * kwh_price * 24 * 30 * 0.2).toFixed(2);
document.getElementById('ebill').value = bill;
}
else {
alert('Please input correct price');
elem.focus();
return false;
}
}

function total() {
var j = 1;
var total_w = 0;
var total_cny = 0;
for (j=1;j<=n_lines;j++) {
var watts = document.getElementById('watts' + j).value;
if(watts.match(numericExpression)) total_w = total_w + parseInt(watts);
var cost = document.getElementById('cost' + j).value;
if(cost.match(numericExpression))total_cny = total_cny + parseInt(cost);
} // end for
document.getElementById('watts_total').value = total_w;
document.getElementById('cost_total').value = total_cny;
price();
}
function count(line) {
var room_size = document.getElementById('size' + line).value;
if (room_size == '') room_size = '0';
if(room_size.match(numericExpression)){

if (room_size > maxroomsize) {
document.getElementById('product' + line).value = "";
document.getElementById('watts' + line).value = "";
document.getElementById('cost' + line).value = "";
total();
alert('Room is too large!');
elem.focus();
return false;
}

var product_type = document.getElementById('room' + line).value;

if (product_type == "lea") {
var i=1
for (i=1;i<=lea_product.length;i++) {
if (room_size <= lea_size[i]) {
document.getElementById('product' + line).value = lea_product[i];
document.getElementById('watts' + line).value = lea_watt[i];
document.getElementById('cost' + line).value = lea_cost[i];
total();
price();
return true;
} // end if
} // end for
}
else if (product_type == "flora") {
var i=1
for (i=1;i<=flora_product.length;i++) {
if (room_size <= flora_size[i]) {
document.getElementById('product' + line).value = flora_product[i];
document.getElementById('watts' + line).value = flora_watt[i];
document.getElementById('cost' + line).value = flora_cost[i];
total();
price();
return true;
} // end if
} // end for
}
else {
document.getElementById('product' + line).value = "";
document.getElementById('watts' + line).value = "";
document.getElementById('cost' + line).value = "";
total();
alert('Please select room type');
elem.focus();
return false;
}

}else{
document.getElementById('product' + line).value = "";
document.getElementById('watts' + line).value = "";
document.getElementById('cost' + line).value = "";
total();
alert('Please input correct room size');
elem.focus();
return false;
}
}
</script>
<p>Select room type and input room size into form to get what product is suitable, cost as well as approximate monthly electricity bill.</p>
<form id="live-quatation" method="post" name="form1" action="">
<table cellspacing="0" cellpadding="0">
<tbody><tr>
<th>Room Type</th>
<th>Size,<br />sqm</th>
<th>Product</th>
<th>Watts/h</th>
<th>Cost</th>
</tr>
<tr>
<td room=""><select id="room1" onchange="count(1)" size="1" name="room1"> <option selected="selected" value="">--Select--</option> <option value="lea">Dinning Room</option> <option value="lea">Living Room</option> <option value="lea">Study</option> <option value="flora">Kitchen</option> <option value="lea">Bedroom</option> <option value="flora">Bathroom</option> </select></td>
<td class="size"><input id="size1" onkeyup="count(1)" name="size1" value="0" type="text" /></td>
<td class="product"><input id="product1" name="product1" readonly="readonly" value="" type="text" /></td>
<td class="watts"><input id="watts1" name="watts1" readonly="readonly" value="" type="text" /></td>
<td class="cost"><input id="cost1" name="cost1" readonly="readonly" value="" type="text" /></td>
</tr>
<tr>
<td room=""><select id="room2" onchange="count(2)" size="1" name="room2"> <option selected="selected" value="">--Select--</option> <option value="lea">Dinning Room</option> <option value="lea">Living Room</option> <option value="lea">Study</option> <option value="flora">Kitchen</option> <option value="lea">Bedroom</option> <option value="flora">Bathroom</option> </select></td>
<td class="size"><input id="size2" onkeyup="count(2)" name="size2" value="0" type="text" /></td>
<td class="product"><input id="product2" name="product2" readonly="readonly" value="" type="text" /></td>
<td class="watts"><input id="watts2" name="watts2" readonly="readonly" value="" type="text" /></td>
<td class="cost"><input id="cost2" name="cost2" readonly="readonly" value="" type="text" /></td>
</tr>
<tr>
<td room=""><select id="room3" onchange="count(3)" size="1" name="room3"> <option selected="selected" value="">--Select--</option> <option value="lea">Dinning Room</option> <option value="lea">Living Room</option> <option value="lea">Study</option> <option value="flora">Kitchen</option> <option value="lea">Bedroom</option> <option value="flora">Bathroom</option> </select></td>
<td class="size"><input id="size3" onkeyup="count(3)" name="size3" value="0" type="text" /></td>
<td class="product"><input id="product3" name="product3" readonly="readonly" value="" type="text" /></td>
<td class="watts"><input id="watts3" name="watts3" readonly="readonly" value="" type="text" /></td>
<td class="cost"><input id="cost3" name="cost3" readonly="readonly" value="" type="text" /></td>
</tr>
<tr>
<td room=""><select id="room4" onchange="count(4)" size="1" name="room4"> <option selected="selected" value="">--Select--</option> <option value="lea">Dinning Room</option> <option value="lea">Living Room</option> <option value="lea">Study</option> <option value="flora">Kitchen</option> <option value="lea">Bedroom</option> <option value="flora">Bathroom</option> </select></td>
<td class="size"><input id="size4" onkeyup="count(4)" name="size4" value="0" type="text" /></td>
<td class="product"><input id="product4" name="product4" readonly="readonly" value="" type="text" /></td>
<td class="watts"><input id="watts4" name="watts4" readonly="readonly" value="" type="text" /></td>
<td class="cost"><input id="cost4" name="cost4" readonly="readonly" value="" type="text" /></td>
</tr>
<tr>
<td room=""><select id="room5" onchange="count(5)" size="1" name="room5"> <option selected="selected" value="">--Select--</option> <option value="lea">Dinning Room</option> <option value="lea">Living Room</option> <option value="lea">Study</option> <option value="flora">Kitchen</option> <option value="lea">Bedroom</option> <option value="flora">Bathroom</option> </select></td>
<td class="size"><input id="size5" onkeyup="count(5)" name="size5" value="0" type="text" /></td>
<td class="product"><input id="product5" name="product5" readonly="readonly" value="" type="text" /></td>
<td class="watts"><input id="watts5" name="watts5" readonly="readonly" value="" type="text" /></td>
<td class="cost"><input id="cost5" name="cost5" readonly="readonly" value="" type="text" /></td>
</tr>
<tr>
<td room=""><select id="room6" onchange="count(6)" size="1" name="room6"> <option selected="selected" value="">--Select--</option> <option value="lea">Dinning Room</option> <option value="lea">Living Room</option> <option value="lea">Study</option> <option value="flora">Kitchen</option> <option value="lea">Bedroom</option> <option value="flora">Bathroom</option> </select></td>
<td class="size"><input id="size6" onkeyup="count(6)" name="size6" value="0" type="text" /></td>
<td class="product"><input id="product6" name="product6" readonly="readonly" value="" type="text" /></td>
<td class="watts"><input id="watts6" name="watts6" readonly="readonly" value="" type="text" /></td>
<td class="cost"><input id="cost6" name="cost6" readonly="readonly" value="" type="text" /></td>
</tr>
<tr>
<td room=""><select id="room7" onchange="count(7)" size="1" name="room7"> <option selected="selected" value="">--Select--</option> <option value="lea">Dinning Room</option> <option value="lea">Living Room</option> <option value="lea">Study</option> <option value="flora">Kitchen</option> <option value="lea">Bedroom</option> <option value="flora">Bathroom</option> </select></td>
<td class="size"><input id="size7" onkeyup="count(7)" name="size7" value="0" type="text" /></td>
<td class="product"><input id="product7" name="product7" readonly="readonly" value="" type="text" /></td>
<td class="watts"><input id="watts7" name="watts7" readonly="readonly" value="" type="text" /></td>
<td class="cost"><input id="cost7" name="cost7" readonly="readonly" value="" type="text" /></td>
</tr>
<tr>
<td room=""><select id="room8" onchange="count(8)" size="1" name="room8"> <option selected="selected" value="">--Select--</option> <option value="lea">Dinning Room</option> <option value="lea">Living Room</option> <option value="lea">Study</option> <option value="flora">Kitchen</option> <option value="lea">Bedroom</option> <option value="flora">Bathroom</option> </select></td>
<td class="size"><input id="size8" onkeyup="count(8)" name="size8" value="0" type="text" /></td>
<td class="product"><input id="product8" name="product8" readonly="readonly" value="" type="text" /></td>
<td class="watts"><input id="watts8" name="watts8" readonly="readonly" value="" type="text" /></td>
<td class="cost"><input id="cost8" name="cost8" readonly="readonly" value="" type="text" /></td>
</tr>
<tr>
<td room=""><select id="room9" onchange="count(9)" size="1" name="room9"> <option selected="selected" value="">--Select--</option> <option value="lea">Dinning Room</option> <option value="lea">Living Room</option> <option value="lea">Study</option> <option value="flora">Kitchen</option> <option value="lea">Bedroom</option> <option value="flora">Bathroom</option> </select></td>
<td class="size"><input id="size9" onkeyup="count(9)" name="size9" value="0" type="text" /></td>
<td class="product"><input id="product9" name="product9" readonly="readonly" value="" type="text" /></td>
<td class="watts"><input id="watts9" name="watts9" readonly="readonly" value="" type="text" /></td>
<td class="cost"><input id="cost9" name="cost9" readonly="readonly" value="" type="text" /></td>
</tr>
<tr>
<td room=""><select id="room10" onchange="count(10)" size="1" name="room10"> <option selected="selected" value="">--Select--</option> <option value="lea">Dinning Room</option> <option value="lea">Living Room</option> <option value="lea">Study</option> <option value="flora">Kitchen</option> <option value="lea">Bedroom</option> <option value="flora">Bathroom</option> </select></td>
<td class="size"><input id="size10" onkeyup="count(10)" name="size10" value="0" type="text" /></td>
<td class="product"><input id="product10" name="product10" readonly="readonly" value="" type="text" /></td>
<td class="watts"><input id="watts10" name="watts10" readonly="readonly" value="" type="text" /></td>
<td class="cost"><input id="cost10" name="cost10" readonly="readonly" value="" type="text" /></td>
</tr>
<tr>
<td style="text-align: right; font-weight: bold;" colspan="3">Total:</td>
<td class="watts"><input id="watts_total" name="watts_total" readonly="readonly" value="0" type="text" /></td>
<td class="cost"><input id="cost_total" name="cost_total" readonly="readonly" value="0" type="text" /></td>
</tr>
<tr class="result">
<td style="text-align: right;" colspan="3">Price for 1kW/h:</td>
<td><input id="kwh_price" onkeyup="price()" name="kwh_price" value="0.5" type="text" /></td>
<td> </td>
</tr>
<tr class="result">
<td style="text-align: right;" colspan="3">Monthly Heating Electricity Bill:</td>
<td><input id="ebill" name="ebill" readonly="readonly" value="0.00" type="text" /></td>
<td> </td>
</tr>
</tbody></table>
</form>

Link to comment
Share on other sites

4 answers to this question

Recommended Posts

  • 0
http://aquaworld.markiz.net/javascript/ - страница Wordpress (это не та страница, на которой скрипт должен быть размещен, но проблема та же, WordPress 3.5.1), http://aquaworld.markiz.net/lq.html - простая html страница
Link to comment
Share on other sites

  • 0

2013-02-22_112143.1361517750.jpg

Как я понимаю вы вставляете ваш код через визуальный редактор.И смотря на скриншот отладчика вам должна быть понятна проблема. Не делайте так. Визуальный редактор должен позволять вставку в режиме исходного кода, вставляйте ваш код именно в режиме исходного кода.

2013-02-22_113207.1361518342.jpg

Если не получается то ваш javascript код вынесите в отдельный файл и в вставляйте его так:


<script type="text/javascript" src="myscript.js"></script>

Edited by wwt
Link to comment
Share on other sites

  • 0

Ох, теперь поняла в чем дело. Спасибо большое за подсказку - оказывается Wordpress автомотически расставил теги <p></p>, хотя код вставляла на страницу в текстовом редакторе, а не визуальном. По вашему совету, вынесла скрипт в отдельный файл и теперь все встало на места.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. See more about our Guidelines and Privacy Policy