Jump to content

Javascript Help Please...


Recommended Posts

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.

Link to comment
Share on other sites

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" )
Link to comment
Share on other sites

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...
Link to comment
Share on other sites

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 ?
Link to comment
Share on other sites

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>
Link to comment
Share on other sites

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.

 

 

 

MayMusic.png

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

&& 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>
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
Reply to this topic...

×   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.

Loading...
×
×
  • Create New...