BullGuard Antivirus Sale - 60% Off with openElement !
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: Nov 25 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: Nov 25 2020 at 8:43pm
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: Jun 05 2018
Location: Canada, Québec
Status: Offline
Points: 6195
Post Options Post Options   Thanks (0) Thanks(0)   Quote Hobby001 Quote  Post ReplyReply Direct Link To This Post Posted: Nov 25 2020 at 8:59pm
Hi,

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

Joined: Jun 05 2018
Location: Canada, Québec
Status: Offline
Points: 6195
Post Options Post Options   Thanks (0) Thanks(0)   Quote Hobby001 Quote  Post ReplyReply Direct Link To This Post Posted: Nov 25 2020 at 9:03pm
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 - Nov 25 2020 at 9:22pm
Back to Top
sevens View Drop Down
Newbie
Newbie
Avatar

Joined: Nov 25 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: Nov 25 2020 at 9:22pm
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: Nov 25 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: Nov 25 2020 at 9:27pm
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: Jun 05 2018
Location: Canada, Québec
Status: Offline
Points: 6195
Post Options Post Options   Thanks (0) Thanks(0)   Quote Hobby001 Quote  Post ReplyReply Direct Link To This Post Posted: Nov 25 2020 at 9:32pm
Back to Top
Hobby001 View Drop Down
Admin Group
Admin Group
Avatar

Joined: Jun 05 2018
Location: Canada, Québec
Status: Offline
Points: 6195
Post Options Post Options   Thanks (0) Thanks(0)   Quote Hobby001 Quote  Post ReplyReply Direct Link To This Post Posted: Nov 25 2020 at 10:28pm
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 - Nov 25 2020 at 10:31pm
Back to Top
Hobby001 View Drop Down
Admin Group
Admin Group
Avatar

Joined: Jun 05 2018
Location: Canada, Québec
Status: Offline
Points: 6195
Post Options Post Options   Thanks (0) Thanks(0)   Quote Hobby001 Quote  Post ReplyReply Direct Link To This Post Posted: Nov 25 2020 at 10:32pm
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: Nov 25 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: Nov 26 2020 at 6:05am
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: Jun 05 2018
Location: Canada, Québec
Status: Offline
Points: 6195
Post Options Post Options   Thanks (0) Thanks(0)   Quote Hobby001 Quote  Post ReplyReply Direct Link To This Post Posted: Nov 26 2020 at 7:58am
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 - Nov 26 2020 at 8:06am
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 12.04
Copyright ©2001-2021 Web Wiz Ltd.

This page was generated in 0.078 seconds.