vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   calculator (https://vborg.vbsupport.ru/showthread.php?t=171116)

StakingAces 02-21-2008 05:56 PM

calculator
 
I have come up with a calculator I wish to add to one of my threads for my members to use in that thread. Here is the PHP I have come up with:
<html>
<body>
<?php
$stake = $_POST['stake'];
$cash = $_POST['cash'];
$newline = "<br/>";

$newline;$newline;
if( is_numeric($cash) && is_numeric($stake) )


{

{
$horseshare = $cash/2-$stake/2;
$stakershare = $horseshare + $stake;

echo "You need to ship: \$".$stakershare.$newline;
echo "You keep: \$".$horseshare.$newline.$newline;

}
}
else{ echo("Invalid entry - please retry"); }
?>

<a href="http://www.stakingaces.com"> Back to Index </a>
</body></html>

Can someone just steer me as to the whereabouts I should load this?

--------------- Added [DATE]1203623838[/DATE] at [TIME]1203623838[/TIME] ---------------

It's basically a formula we use there but I want it to be able to be embedded in a thread for them to use on site instead of having to pull up their own calculator and messing the formula up and us having to correct it within the thread each time.

--------------- Added [DATE]1203650350[/DATE] at [TIME]1203650350[/TIME] ---------------

I actually had someone come up with a java code for me to use but its not accepting the user code. Any ideas as to why?

<html>
<head>
<script type="text/javascript">
<!--

function calculate(task){
var f1 = document.getElementById("stake");
var f2 = document.getElementById("cash");
var f3 = document.getElementById("horseshare");
var f4 = document.getElementById("stakershare");
var f5 = document.getElementById("siteshare");


if(!isNumber(f1.value) || !isNumber(f2.value))
alert("Invalid field entry!");
else{
if(task == "compute")
{
f5.value = f2.value *.05;
f2.value = f2.value *.95;
f3.value = f2.value/2 - f1.value/2;
f4.value = f3.value + f1.value;


}
if(task == "reset"){
f1.value = "";
f2.value = "";
f3.value = "";
f4.value = "";
f5.value = "";
}


}
}
}
-->
</script>
</head>
<body>
<TABLE width=200 height=100 >
<TR>
<TD >
Amount of stake: <input type="Text" id="stake"></br>

Total Amount Cashed: <input type="text" id="cash">
</br>
<input value="Calculate" type="button" onclick="calculate('compute')"/>
<input type="button" value="Clear Fields" onclick="calculate('reset')" />
</br></br></br>
Total to be shipped to site: <input type="text" id="siteshare"></br>
Total to be shipped to staker: <input type="text" id="stakershare"></br>
Total to keep: <input type="text" id="horseshare">
</TR>
</TD>



</TABLE>
</body>
</html>

--------------- Added [DATE]1203650384[/DATE] at [TIME]1203650384[/TIME] ---------------

not accepting the user input, sorry.

--------------- Added [DATE]1203651724[/DATE] at [TIME]1203651724[/TIME] ---------------

any help ANYONE can give me on this who knows about this would be greatly appreciated.

cheesegrits 02-22-2008 05:27 PM

Several problems. You had an extra closing } in the function which was throwing a javascript error. Also there is no such built in javascript function isNumber(), so that was blowing up. Also you have the test for the 'invalid input' in the wrong place (no point checking for valid fields when you are clearing the form).

Try this:

HTML Code:

<html>
<head>
<script type="text/javascript">
<!--

function calculate(task){
        var f1 = document.getElementById("stake");
        var f2 = document.getElementById("cash");
        var f3 = document.getElementById("horseshare");
        var f4 = document.getElementById("stakershare");
        var f5 = document.getElementById("siteshare");

        if(task == "compute")
        {
                if(isNaN(f1.value) || isNaN(f2.value))
                        alert("Invalid field entry!");
                else
                {
                        f5.value = f2.value *.05;
                        f2.value = f2.value *.95;
                        f3.value = f2.value/2 - f1.value/2;
                        f4.value = f3.value + f1.value;
                }
        }
        if(task == "reset")
        {
                f1.value = "";
                f2.value = "";
                f3.value = "";
                f4.value = "";
                f5.value = "";
        }
}
-->

</script>
</head>
<body>
<TABLE width=200 height=100 >
<TR>
<TD >
Amount of stake: <input type="Text" id="stake"></br>

Total Amount Cashed: <input type="text" id="cash">
</br>
<input value="Calculate" type="button" onclick="calculate('compute')"/>
<input type="button" value="Clear Fields" onclick="calculate('reset')" />
</br></br></br>
Total to be shipped to site: <input type="text" id="siteshare"></br>
Total to be shipped to staker: <input type="text" id="stakershare"></br>
Total to keep: <input type="text" id="horseshare">
</TR>
</TD>



</TABLE>
</body>
</html>

-- hugh

StakingAces 02-23-2008 12:04 AM

Ok, thanks a ton Hugh. We're working on this now, still have a few problems with it actually adding the numbers we input. If we get stuck, I'll update you on where we're stuck - (if you're still willing to help me out that is) Thanks again man! Ben

cheesegrits 02-23-2008 12:32 AM

No problem. It does fill in numbers on the test page I made, but they look pretty whacked! I guess you just need to tweak your math a little. :)

-- hugh

StakingAces 02-23-2008 12:42 AM

Ok, here's where we're stuck....

" its f4.value and redoing f2.value after it
they're not adding
the () in them i added to try to calculate
also tried "" and spacing different
those two dont compute just attach "

--------------- Added [DATE]1203738499[/DATE] at [TIME]1203738499[/TIME] ---------------

I dont know, we just can't get it to compute - just mashes all the numbers together.

--------------- Added [DATE]1203742838[/DATE] at [TIME]1203742838[/TIME] ---------------

ok heres the updated code but it still wont add, it just combines - its 99% done but we cant get this...

<html>
<head>
<script type="text/javascript">
<!--

function calculate(task){
var f1 = document.getElementById("stake");
var f2 = document.getElementById("cash");
var f3 = document.getElementById("horseshare");
var f4 = document.getElementById("stakershare");
var f5 = document.getElementById("siteshare");

if(task == "compute")
{
if(isNaN(f1.value) || isNaN(f2.value))
alert("Invalid field entry!");
else
{

f3.value = (f2.value - f1.value)/2;
f5.value = (f3.value)*.05;
f3.value = f3.value - f5.value;

//@%@#% f4.value = f3.value + f1.value;


}
}
if(task == "reset")
{
f1.value = "";
f2.value = "";
f3.value = "";
f4.value = "";
f5.value = "";
}
}
-->
</script>
</head>
<body>
<TABLE width=200 height=100 >
<TR>
<TD >
Amount of stake: <input type="Text" id="stake"></br>

Total Amount Cashed: <input type="text" id="cash">
</br>
<input value="Calculate" type="button" onclick="calculate('compute')"/>
<input type="button" value="Clear Fields" onclick="calculate('reset')"/>
</br></br></br>
Total to be shipped to site: <input type="text" id="siteshare"></br>
Total to be shipped to staker: <input type="text" id="stakershare"></br>
Total to keep: <input type="text" id="horseshare">
</TR>
</TD>



</TABLE>
</body>
</html>

--------------- Added [DATE]1203756324[/DATE] at [TIME]1203756324[/TIME] ---------------

Ok, I think we got it - now heres the noob part lol - can you tell me the exact steps I need to take to try it out on my forum? I want it to be available as a sticky in one forum. Heres the code BTW Hugh....

<html>
<head>
<script type="text/javascript">
<!--

function calculate(task){
var f1 = document.getElementById("stake");
var f2 = document.getElementById("cash");
var f3 = document.getElementById("horseshare");
var f4 = document.getElementById("stakershare");
var f5 = document.getElementById("siteshare");
var f6 = document.getElementById("adjustedhorse");

if(task == "compute")
{
if(isNaN(f1.value) || isNaN(f2.value))
alert("Invalid field entry!");
else
{

f6.value = ((f2.value - f1.value)/2).toFixed(2);
f5.value = ((f6.value)*.05).toFixed(2);
f3.value = ((f6.value - f5.value)).toFixed(2);
f4.value = ((f6.value *1)+(f1.value*1)).toFixed(2);

}
}
if(task == "reset")
{
f1.value = "";
f2.value = "";
f3.value = "";
f4.value = "";
f5.value = "";
}
}
-->
</script>
</head>
<body>
<TABLE width=200 height=100 >
<TR>
<TD >
Amount of stake: <br>$<input type="Text" id="stake"><br>

Total Amount Cashed: <br>$<input type="text" id="cash">
<br>
<input value="Calculate" type="button" onclick="calculate('compute')">
<input type="button" value="Clear Fields" onclick="calculate('reset')">
<br><br><br>
Total to be shipped to site:<br> $<input type="text" id="siteshare"><br>
Total to be shipped to staker:<br> $<input type="text" id="stakershare"><br>
<input type="hidden" id="adjustedhorse">
Total to keep:<br> $<input type="text" id="horseshare">
</TR>
<TD>



</TABLE>
</body>
</html>

--------------- Added [DATE]1203784756[/DATE] at [TIME]1203784756[/TIME] ---------------

I actually finished this and thank you Hugh for all your help. Can an admin please remove this now. Thank you.


All times are GMT. The time now is 10:56 AM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01163 seconds
  • Memory Usage 1,752KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)bbcode_html_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (5)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete