BullGuard Antivirus Sale - 60% Off with openElement !
Forum openElement Homepage
Forum Home Forum Home >

openElement

> Scripts for Your Website
  New Posts New Posts RSS Feed - Calculation script
  FAQ FAQ  Forum Search   Register Register  Login Login

Calculation script

 Post Reply Post Reply Page  12>
Author
Message
sevens View Drop Down
Newbie
Newbie
Avatar

Joined: 25 Nov 2020
Location: Namibia
Status: Offline
Points: 8
Post Options Post Options   Thanks (0) Thanks(0)   Quote sevens Quote  Post ReplyReply Direct Link To This Post Topic: Calculation script
    Posted: 25 Nov 2020 at 21:43
Hi, need help with a calculation on a page, no scripting knowledge or where and how to place such script in OE.

I have 4 elements on a page as follows:
dropdown list with id: combo_primer
text input field with id: edit_primer_width
text input field with id: edit_primer_height
text input field with id: edit_primer_qty_calc

I want to calculate as follows when a key is pressed in any one of the text input fields, or an item is selected in the dropdown list:

if combo_primer items 1 is selected then
edit_primer_qty_calc.value = roundup (edit_primer_width.value * edit_primer_height.value) / 3.6

if anyone can assist in detail, thank you



Riaan S
Back to Top
Hobby001 View Drop Down
Admin Group
Admin Group
Avatar

Joined: 05 Juin 2018
Location: Canada, Québec
Status: Online
Points: 5447
Post Options Post Options   Thanks (0) Thanks(0)   Quote Hobby001 Quote  Post ReplyReply Direct Link To This Post Posted: 25 Nov 2020 at 21:59
Hi,

Can you post a link to your page?
Back to Top
Hobby001 View Drop Down
Admin Group
Admin Group
Avatar

Joined: 05 Juin 2018
Location: Canada, Québec
Status: Online
Points: 5447
Post Options Post Options   Thanks (0) Thanks(0)   Quote Hobby001 Quote  Post ReplyReply Direct Link To This Post Posted: 25 Nov 2020 at 22:03
What do you want to do with the calculated result?  Display it on the page?

Ok, I saw it in yout text input field list


Edited by Hobby001 - 25 Nov 2020 at 22:22
Back to Top
sevens View Drop Down
Newbie
Newbie
Avatar

Joined: 25 Nov 2020
Location: Namibia
Status: Offline
Points: 8
Post Options Post Options   Thanks (0) Thanks(0)   Quote sevens Quote  Post ReplyReply Direct Link To This Post Posted: 25 Nov 2020 at 22:22
Hi Hobby001,

The url to the page:

http://nomax.group/Paint%20Calculator.htm

Thanks, Riaan
Riaan S
Back to Top
sevens View Drop Down
Newbie
Newbie
Avatar

Joined: 25 Nov 2020
Location: Namibia
Status: Offline
Points: 8
Post Options Post Options   Thanks (0) Thanks(0)   Quote sevens Quote  Post ReplyReply Direct Link To This Post Posted: 25 Nov 2020 at 22:27
Yes,

Want to display the calculated result in the text input field with id: edit_primer_qty_calc, to the far right

I see it is currently -4 in Quebec, isshhh. Would love to be able to immigrate to Canada.

Thanks,

Riaan
Riaan S
Back to Top
Hobby001 View Drop Down
Admin Group
Admin Group
Avatar

Joined: 05 Juin 2018
Location: Canada, Québec
Status: Online
Points: 5447
Post Options Post Options   Thanks (0) Thanks(0)   Quote Hobby001 Quote  Post ReplyReply Direct Link To This Post Posted: 25 Nov 2020 at 22:32
Back to Top
Hobby001 View Drop Down
Admin Group
Admin Group
Avatar

Joined: 05 Juin 2018
Location: Canada, Québec
Status: Online
Points: 5447
Post Options Post Options   Thanks (0) Thanks(0)   Quote Hobby001 Quote  Post ReplyReply Direct Link To This Post Posted: 25 Nov 2020 at 23:28
Ok, here is the code:

$('#WEcombo_primer select').change(
function(){
var $area = 0;
if($(this).val()=="Bonding Plaster Primer"){
$area = $('#WEedit_primer_width input').val() * $('#WEedit_primer_height input').val();
if ($area>0){
$('#WEedit_primer_qty_calc input').val(Math.ceil($area / 3.6));
}
}
}
);


If width or hight = 0, nothing will happend since there is no sense dividing 0 by 3.6





Edited by Hobby001 - 25 Nov 2020 at 23:31
Back to Top
Hobby001 View Drop Down
Admin Group
Admin Group
Avatar

Joined: 05 Juin 2018
Location: Canada, Québec
Status: Online
Points: 5447
Post Options Post Options   Thanks (0) Thanks(0)   Quote Hobby001 Quote  Post ReplyReply Direct Link To This Post Posted: 25 Nov 2020 at 23:32
You have to add a javascript code block in EndBody position to your page and insert this code into it


Back to Top
sevens View Drop Down
Newbie
Newbie
Avatar

Joined: 25 Nov 2020
Location: Namibia
Status: Offline
Points: 8
Post Options Post Options   Thanks (0) Thanks(0)   Quote sevens Quote  Post ReplyReply Direct Link To This Post Posted: 26 Nov 2020 at 07:05
Thank you so much for your help, works 100%, appreciated. 

How do I trigger the same calculation for any key press in the edit_primer_width & edit_primer_height edit boxes?
Riaan S
Back to Top
Hobby001 View Drop Down
Admin Group
Admin Group
Avatar

Joined: 05 Juin 2018
Location: Canada, Québec
Status: Online
Points: 5447
Post Options Post Options   Thanks (0) Thanks(0)   Quote Hobby001 Quote  Post ReplyReply Direct Link To This Post Posted: 26 Nov 2020 at 08:58
First add a custom class named Chosen_Fields to your two size input fields

then replace the javascript code this way:


// Action calculation on drop list change
$('#WEcombo_primer select').change(
function(){
calculate_quantity();
}
);

// Action calculation after each key up in selected input fields
$('.Chosen_Fields input').keyup(
function(){
calculate_quantity();
}
);

// update calculated field
function calculate_quantity(){
var $area = 0;
// if drop list selection is ok
if($('#WEcombo_primer select').val()=="Bonding Plaster Primer"){
$area = $('#WEedit_primer_width input').val() * $('#WEedit_primer_height input').val();
if ($area>0){
$('#WEedit_primer_qty_calc input').val(Math.ceil($area / 3.6));
}
} else {
$('#WEedit_primer_qty_calc input').val("");
}
}



You may also check the read-only check box for your WEedit_primer_qty_calc field




Edited by Hobby001 - 26 Nov 2020 at 09:06
Back to Top
 Post Reply Post Reply Page  12>
  Share Topic   

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 10.11
Copyright ©2001-2012 Web Wiz Ltd.

This page was generated in 0,047 seconds.