/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] Mathematical PHP / Javascript problem

If a user decides to pay for their insurance via direct debit a 7% interest charge is applied to their total.

i have the following code in place:

[code=php]
if ((isset($_POST[‘mySelect’])) == ‘ddm’)
{
$pretotal = $total * (7/100);
$ddm_total = $total + $pretotal;
}
[/code]

this only runs when the form is submitted.

the selectbox it applies to is:

[code=php]
<select id=”mySelect” name=”mySelect” size=”1″ onclick=”return displayDiv(this.selectedIndex)” value=’$mySelect’ title=”Your Payment Method”>
<option value=”0″ <? if(isset($_SESSION[‘mySelect’]) && $_SESSION[‘mySelect’] == ‘0’) { ?>selected=”selected”<? } ?> />Please Select…</option>
<option value=”ddm” <? if(isset($_SESSION[‘mySelect’]) && $_SESSION[‘mySelect’] == ‘ddm’) { ?>selected=”selected”<? } ?> />Direct Debit</option>
<option value=”cc” <? if(isset($_SESSION[‘mySelect’]) && $_SESSION[‘mySelect’] == ‘cc’) { ?>selected=”selected”<? } ?> />Credit Card</option>
</select>
[/code]

the dilema i have is the onClick command is being used for the function to display either method of paying.

has anyone any suggestions?

to post a comment
PHP

6 Comments(s)

Copy linkTweet thisAlerts:
@JonaMar 01.2006 — [font=trebuchet ms]Maybe calculate the subtotal via JavaScript [i]and[/i] via PHP?[/font]
Copy linkTweet thisAlerts:
@NogDogMar 01.2006 — I don't think this does what you think it does:
[code=php]
if ((isset($_POST['mySelect'])) == 'ddm')
[/code]

Just run this little test:
[code=php]
<?php
if((isset($test)) == 99)
{
echo "<p>Evaluated as true</p>n";
}
else
{
echo "<p>Evaluated as false</p>n";
}
$test = 99;
if((isset($test)) == 99)
{
echo "<p>Evaluated as true</p>n";
}
else
{
echo "<p>Evaluated as false</p>n";
}
$test = 10;
if((isset($test)) == 99)
{
echo "<p>Evaluated as true</p>n";
}
else
{
echo "<p>Evaluated as false</p>n";
}
?>
[/code]

You'll see that it outputs:

Evaluated as false

Evaluated as true

Evaluated as true
[/quote]

You'll need to do something like:
[code=php]
if (isset($_POST['mySelect']) and $_POST['mySelect'] == 'ddm')
[/code]
Copy linkTweet thisAlerts:
@peteybauthorMar 01.2006 — Good help NogDog. Will implement across my code.

Got a really easy question but im just being a bit dense, how can i round the resultant to two decimal places?
Copy linkTweet thisAlerts:
@NogDogMar 01.2006 — Good help NogDog. Will implement across my code.

Got a really easy question but im just being a bit dense, how can i round the resultant to two decimal places?[/QUOTE]

It's a function you'll never guess the name of: [url=http://www.php.net/round]round()[/url] ?
Copy linkTweet thisAlerts:
@SheldonMar 01.2006 — http://php.net/round


EDIT : Wooooops, took so long rading the thread NogDon had alreay answered it ?
Copy linkTweet thisAlerts:
@peteybauthorMar 01.2006 — hehe
×

Success!

Help @peteyb 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.27,
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,
)...