Jump to content

Simple JavaScript question


Sophia

Recommended Posts

I'm not sure where to post this question... it has more to do with JavaScript then WHMCS.

 

A little background: a while ago I purchased the custom mod to compare plans. I set it up, but now decided to break down my pricing in monthly sections, offering a discount the longer people subscribe.

 

Anyway... what I really wish to do, is break down the pricing in the compare template, but I don't think it is possible.

 

If I look in the list of smarty tags, and found this

 

   [plan1_rawmonthly] => 1.50
   [plan1_rawquarterly] => -1.00
   [plan1_rawsemiannual] => -1.00
   [plan1_rawannual] => 15.00
   [plan1_rawbiennial] => 27.60
   [plan1_rawtriennial] => 36.00

 

Now, here is my real question at last: is it possible to wrap these in some JavaScript, so that I can divide the rawannual by 12, rawbiennial by 24, etc?

 

I am an absolute JavaScript rookie, so if anybody would be so kind to explain how to do that, I'd be eternally grateful 8)

 

I tried

 

<script language="javascript">
function
{$plan1_rawannual}/12
</script>

 

But obviously it's not THAT simple :lol:

 

Thanks!

Link to comment
Share on other sites

Thanks! After a lot of thinking, sweating and Googling (my best friend), I found this solution:

 

	<script language="javascript">
	document.write( '<b>{$currency.prefix} ' + ({$plan1_rawtriennial}/36).toFixed(2) + '</b><br />' );
	document.write( ' ' + ({$plan1_rawbiennial}/24).toFixed(2) + '<br />' ); 
	document.write( ' ' + ({$plan1_rawannual}/12).toFixed(2) + '<br />' );
	document.write( ' ' + ({$plan1_rawmonthly}).toFixed(2) + ' ' );
</script>

 

But yours seems so much more simple and neat :D

 

Just a question, which Smarty template would that be? The compare plans one or...?

Edited by Sophia
Link to comment
Share on other sites

You can also do it in the smarty template

 

Unfortunately, my neat little javascript argues with another element on my page, so, would you kindly tell me which smarty template to edit? I found the includes/smarty folder, but didn't quite see the list of elements.

 

Thanks again for your help 8)

Link to comment
Share on other sites

I seriously love you :D That works great! If I may bug you one last time... how do I make sure it actually displays the amount with 2 digits (1.00 instead of 1 and 2.00 instead of 2.000003)?

 

In JavaScript I found the command is toFixed but I don't know how to do it here... thanks again Sparky!

Link to comment
Share on other sites

  • 9 months later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

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.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated