Accountability Posted August 21, 2013 Report Share Posted August 21, 2013 Please need help with this JS. If the field On_Site_Upcharge_Percentage is greater than or equal to "10" and field Build_On_Site equals "yes", Need to replace field Bldg_Upcharge with the value of ((On_Site_Upcharge_Percentage/100) * Bldg_Base_Price). If the conditions are not met, need to replace Bldg_Upcharge with 0. ************************************************************************************************************************************************************************ <script> if("[@field:Build_On_Site]" == "Yes" && "[@field:On_Site_Upcharge_Percentage]">="10" ){ function concatenate() { var position1 = document.getElementById("InsertRecordOn_Site_Upcharge_Percentage").value; var position2 = document.getElementById("InsertRecordBldg_Base_Price").value; var allpositions = (position1/100) * position2; document.getElementById("InsertRecordBldg_Upcharge").value = allpositions; } document.getElementById("caspioform").onsubmit=concatenate; } else { var position1 = 0 var allpositions = position1; document.getElementById("InsertRecordBldg_Upcharge").value = allpositions; } { document.getElementById("caspioform").onsubmit="0"; } </script> ************************************************************************************************************************************************************************ Very much appreciate anyone's help. Quote Link to comment Share on other sites More sharing options...
MayMusic Posted August 21, 2013 Report Share Posted August 21, 2013 Is it a submission page? If yes, then you need to get the value entered on Build_On_Site and On_Site_Upcharge_Percentage in condition: if ((document.getElementById("InsertRecordBuild_On_Site").value) == "Yes" && (document.getElementById("InsertRecordOn_Site_Upcharge_Percentage").value) >= "10" ) Quote Link to comment Share on other sites More sharing options...
Accountability Posted August 21, 2013 Author Report Share Posted August 21, 2013 Hello MayMusic, Thanks so much for helping ! I was putting this in a HTML footer. Do I still use the syntax you provided ? Just at a glance does the rest of the script look correct ? Thanks again. Quote Link to comment Share on other sites More sharing options...
Accountability Posted August 21, 2013 Author Report Share Posted August 21, 2013 Yes a submission Page. Quote Link to comment Share on other sites More sharing options...
Accountability Posted August 22, 2013 Author Report Share Posted August 22, 2013 Changed to: <script> if ((document.getElementById("InsertRecordBuild_On_Site").value) == "Yes" && (document.getElementById("InsertRecordOn_Site_Upcharge_Percentage").value) >= "10" ){ function concatenate() { var position1 = document.getElementById("InsertRecordOn_Site_Upcharge_Percentage").value; var position2 = document.getElementById("InsertRecordBldg_Base_Price").value; var allpositions = (position1/100) * position2; document.getElementById("InsertRecordBldg_Upcharge").value = allpositions; } document.getElementById("caspioform").onsubmit=concatenate; } else { var position1 = 0 var allpositions = position1; document.getElementById("InsertRecordBldg_Upcharge").value = allpositions; } { document.getElementById("caspioform").onsubmit="0"; } </script> Something still not quite right. Any suggestions ? Thanks again... Quote Link to comment Share on other sites More sharing options...
Accountability Posted August 22, 2013 Author Report Share Posted August 22, 2013 Tried another approach which also didn't work. <SCRIPT LANGUAGE="JavaScript"> function calculate() if ((document.getElementById("InsertRecordBuild_On_Site").value) == "Yes" && (document.getElementById("InsertRecordOn_Site_Upcharge_Percentage").value) >= "10" ) { var v_price = parseFloat(document.getElementById("InsertRecordBldg_Base_Price").value); var v_percent = parseFloat(document.getElementById("InsertRecordOn_Site_Upcharge_Percentage").value); var v_total = (v_price * (v_percent/100)); document.getElementById("InsertRecordBldg_Upcharge").value = Math.round(v_total); } /* On submitting the webform, the function calculate is executed */ document.getElementById("caspioform").onsubmit=calculate; else var v_total = 0; document.getElementById("InsertRecordBldg_Upcharge").value = Math.round(v_total); } /* On submitting the webform, the function calculate is executed */ document.getElementById("caspioform").onsubmit=calculate; </SCRIPT> Any ideas would sure be much appreciated ? Quote Link to comment Share on other sites More sharing options...
MayMusic Posted August 23, 2013 Report Share Posted August 23, 2013 Can you give me the link of the page? Quote Link to comment Share on other sites More sharing options...
MayMusic Posted August 23, 2013 Report Share Posted August 23, 2013 Is Build_On_Site a yes/no field? You can try: <script> function concatenate() { var position1 = document.getElementById("InsertRecordOn_Site_Upcharge_Percentage").value; var position2 = document.getElementById("InsertRecordBldg_Base_Price").value; if ((document.getElementById("InsertRecordBuild_On_Site").value) == "Y" && (document.getElementById("InsertRecordOn_Site_Upcharge_Percentage").value) >= "10" ) { var allpositions = (position1/100) * position2; document.getElementById("InsertRecordBldg_Upcharge").value = allpositions; } else { var allpositions = 0; document.getElementById("InsertRecordBldg_Upcharge").value = allpositions; } } document.getElementById("caspioform").onsubmit=concatenate; </script> Quote Link to comment Share on other sites More sharing options...
Accountability Posted August 24, 2013 Author Report Share Posted August 24, 2013 Hello MayMusic' First of all, I want to thank you for taking the time to help. This is not the first time you have helped me and I see you help a lot of other people. I hope you know how grateful and appreciative I am for you kindness. If I had your e-mail address, I could send you a link and log-in credentials to get to this form. I can't publish this publicly. I certainly do not want to intrude on your privacy so I understand if that is not possible. That said, I have included a screenshot with the fields involved as well as the form section . I tried the suggested JS but not functioning just yet. Once again thanks so much for you help. Quote Link to comment Share on other sites More sharing options...
Accountability Posted August 24, 2013 Author Report Share Posted August 24, 2013 OOPS,,, forgot this field Quote Link to comment Share on other sites More sharing options...
MayMusic Posted August 26, 2013 Report Share Posted August 26, 2013 I am glad if I am a little bit of help You can click on my name and get to the profile and then send me a private message if you do not mind. Quote Link to comment Share on other sites More sharing options...
MayMusic Posted August 27, 2013 Report Share Posted August 27, 2013 For cascadings since ID is being changed on each page load you need to refer to them by name so for instance Best Price is cascading so you need to call it in this format : document.getElementsByName("InsertRecordBldg_Upcharge")[0].value Try to modify the code for all cascading and see if that helps. Quote Link to comment Share on other sites More sharing options...
MayMusic Posted August 27, 2013 Report Share Posted August 27, 2013 I was not able to find all the parameters you are referring to on the page in the code. Can you please specify which parameter is for which field on the page? Quote Link to comment Share on other sites More sharing options...
MayMusic Posted August 27, 2013 Report Share Posted August 27, 2013 Try this: <script> function concatenate() { var position1 = document.getElementById("InsertRecordOn_Site_Upcharge_Percentage").value; var position2 = document.getElementsByName("InsertRecordBldg_Base_Price")[0].value; if ((document.getElementById("InsertRecordBuild_On_Site").value) == "Y" && (document.getElementById("InsertRecordOn_Site_Upcharge_Percentage").value) >= "10" ) { var allpositions = (position1/100) * position2; document.getElementById("InsertRecordBldg_Upcharge").value = allpositions; } else { document.getElementById("InsertRecordBldg_Upcharge").value = '0'; } } document.getElementById("caspioform").onsubmit=concatenate; </script> Also there is no default value for this hidden filed "Bldg_Base_Price" which there should one. So you can either receive the value or assign a static one. Quote Link to comment Share on other sites More sharing options...
Accountability Posted August 28, 2013 Author Report Share Posted August 28, 2013 MayMusic, You are incredible ! It works perfectly now. I have really learned a lot by your example. I can't THANK YOU ENOUGH ! Very Sincerely, Accountability Quote Link to comment Share on other sites More sharing options...
Accountability Posted August 28, 2013 Author Report Share Posted August 28, 2013 If I were to utilize the exact script on the corresponding report datapage, would it just be a matter of changing the word insert to edit ? (There are two other datapages on the same web page.) Quote Link to comment Share on other sites More sharing options...
Accountability Posted August 28, 2013 Author Report Share Posted August 28, 2013 The reason I posted the previous question is because I tried it and it didn't seem to work. Upon closer observation I found a typing error (on my part). Once it was corrected it worked just fine. I do have one question. Does the && in the "if" statement the same function as an .and. booleen operator ? The reason I ask is I tested the condition but it didn't work exactly as I would expect. If Y/N check mark is Y .and. percentage field is greater than or equal to 10, then calculate and insert value into field. else (I would have expected) if either Y/N = N .or. percentage field is .not. >= 10 then insert 0 into field. What is actually taking place is it is properly functioning only when the percentage field is or is .not. >= 10 then insert the calculation or 0 into field. In other words it seems to ignore the Y/N check mark field. Any advise ? Thanks Quote Link to comment Share on other sites More sharing options...
MayMusic Posted August 28, 2013 Report Share Posted August 28, 2013 && in java script is the same as AND and || if OR. You can try to add alerts to the page to see if it gets to the if and what is the value of the checkbox when it gets in the if statement. <script> function concatenate() { var position1 = document.getElementById("InsertRecordOn_Site_Upcharge_Percentage").value; var position2 = document.getElementsByName("InsertRecordBldg_Base_Price")[0].value; alert(document.getElementById("InsertRecordBuild_On_Site").value); if ((document.getElementById("InsertRecordBuild_On_Site").value) == "Y" && (document.getElementById("InsertRecordOn_Site_Upcharge_Percentage").value) >= "10" ) { alert('in if'); var allpositions = (position1/100) * position2; document.getElementById("InsertRecordBldg_Upcharge").value = allpositions; } else { document.getElementById("InsertRecordBldg_Upcharge").value = '0'; } } document.getElementById("caspioform").onsubmit=concatenate; </script> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.