/    Sign up×
Community /Pin to ProfileBookmark

calculator script again

its me again, still on that calculator script, thanks for your help thus far!

I want to make it so that the calculator does not need to reload the page every time a problem is put in. I don’t know if this can be done with php alone, but I just thought that maybe if i set the form to call to a javascript function, in which i stuck the php code, this just might work. The problem then becomes posting the final output to the correct place on the page, and getting the notation for the javascript function down.

[code=php]
<?php

if(isset($_POST[‘calc’])){
$hist = $_POST[‘hist’];
$calc = $_POST[‘calc’];
eval(“$result=” . $calc . “;”);
$hist = $hist . $calc. ” = ” . $result . “<br>”;
echo $hist ;
}

?>

<form method=”post” action=”<?php echo $_SERVER[‘PHP_SELF’] ?>”>
<input type=”hidden” name=”hist” value=”<?php echo($hist); ?>”>
<input type=”text” name=”calc” size=”50″><br>
<input type=”submit” value=”solve”>
</form>
[/code]

that’s the current source. If there is a better way to do this (not what i already have, but what i am trying to accomplish), using only php, please tell me if not, any ideas on how I can make this work?

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@SpectreReturnsMar 05.2005 — [i]Originally posted by gameguy43 [/i]

[B]its me again, still on that calculator script, thanks for your help thus far!



I want to make it so that the calculator does not need to reload the page every time a problem is put in. I don't know if this can be done with php alone, but I just thought that maybe if i set the form to call to a javascript function, in which i stuck the php code, this just might work. The problem then becomes posting the final output to the correct place on the page, and getting the notation for the javascript function down.



[code=php]
<?php

if(isset($_POST['calc'])){
$hist = $_POST['hist'];
$calc = $_POST['calc'];
eval("$result=" . $calc . ";");
$hist = $hist . $calc. " = " . $result . "<br>";
echo $hist ;
}

?>

<form method="post" action="<?php echo $_SERVER['PHP_SELF'] ?>">
<input type="hidden" name="hist" value="<?php echo($hist); ?>">
<input type="text" name="calc" size="50"><br>
<input type="submit" value="solve">
</form>
[/code]


that's the current source. If there is a better way to do this (not what i already have, but what i am trying to accomplish), using only php, please tell me if not, any ideas on how I can make this work? [/B][/QUOTE]


There is no way to change a PHP page without reloading (unless you're using sockets). Why don't you just write the whole thing in JavaScript? It would be easier..
Copy linkTweet thisAlerts:
@NogDogMar 05.2005 — [i]Originally posted by SpectreReturns [/i]

[B]There is no way to change a PHP page without reloading (unless you're using sockets). Why don't you just write the whole thing in JavaScript? It would be easier.. [/B][/QUOTE]

It would be, however, less accessible (not everyone has JavaScript available or activated on his/her browser). But this is the price you pay for using a server-side script: you have to converse with the server to run it. With a reasonably lean HTML output and reasonably efficient code on the server side, this is usually not really much of a problem.

If you use a CSS stylesheet to control the design/layout of the page, you can reduce the amount of data that gets transferred on each subsequent page request (the browser will cache the stylesheet) plus the actual HTML can be kept more streamlined.
Copy linkTweet thisAlerts:
@gameguy43authorMar 05.2005 — interesting... so i guess i can't just completely substitute php for javascript... thanks
×

Success!

Help @gameguy43 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...