/    Sign up×
Community /Pin to ProfileBookmark

Need some help please

Hy,
Im new to JavaScript and have some question on it.
I have one page that includes java script it is HTML. my script have to do next:
To ask number of clients
to calculate the price and to dysplay result when i press calculate button the code i have write is here too so please tell me whats wrog
:
// JavaScript Document
function Validate(){
if (document.form1.pices.value < 5)
document.form1.pices.value = 5;
}
function CalculatePrice(){
if (document.form1.pices.value = 5)
calculation = 100 + (document.form1.pices.value * 12);
document.form1.result.value == calculation;
if (document.form1.pices.value >= 6 && document.form1.pices.value <= 10)
calculation = 100 + (document.form1.pices.value *
10);
document.form1.result.value == calculation;
}

And next thing is that i have to do the check button for 2 ways of pay. if first is selected the price calculated above must be pased to a link of order page when i press continue button:
Thanx in advance

to post a comment
JavaScript

7 Comments(s)

Copy linkTweet thisAlerts:
@jdorfJan 04.2005 — can you also post your form?
Copy linkTweet thisAlerts:
@jvsonicauthorJan 04.2005 — I have remake it a bit but i get some other mistaces.

// JavaScript Document

function Validate(){

if (document.form1.pices.value <= 5){

document.form1.pices.value = 5;

}

else {

document.form1.pices.value;

}

}

function CalculatePrice(){

if (document.form1.pices.value = 5){

calculation = 100 + (document.form1.pices.value * 12);

document.form1.result.value = calculation;

}

if ((document.form1.pices.value >= 6) && (document.form1.pices.value <= 10)){

calculation = 100 + (document.form1.pices.value *
10);

document.form1.result.value = calculation;

}

}

This is the code

Naw i have some more problems the firs is when i enter number more then5 if returns it to 5 and calculate price for onley 5 clients

the seconde is that it dont calculate price for more than 5 clients.
Copy linkTweet thisAlerts:
@jvsonicauthorJan 04.2005 — <form name="form1" method="get" action="">

<font size="2">Follow these steps to order Cyberleader Software:</font>

<p> <b> <font size="2">Step 1 - Price Calculation</font></b></p>

<p><font size="2"> Number of client computers that you have:

</font>

<input name="pices" size="6" type="text" onChange="Validate()">

<input name="calculate" type="Button" id="calculate" value="Calculate Price" onClick="CalculatePrice()">

<font size="2"><br>

(minimum number is 5).</font></p>

<p><b><font size="2">Total price:

<input name="result" type="text" id="result" size="8" maxlength="8">

</font></b></p>

<p><b><font size="2">Step 2 - Choose a Payment Method:</font></b></p>

</form></td>

And here is the online page that i am talking about:

http://www.cyberleader.net/order_1.htm

The price is to be calculated as a base price for the server ($100) + Number

of the clients * the price of each client. The price of each client changes

as the number of clients increases. For first 5 Clients, the price/unit is

$12 (total price is $160). Then the price of 6-10 Clients is $10 each (total

price is $200). I will do the rest myself as I am familiar with JavaScript a

little bit. The minimum number of Clients is 5, so if they enter, for

example, 3, make it 5. "Total price:" should NOT be visible at first. It

should appear only when they press "Calculate price". Use the document.write

function.

For shareit, when they press Continue, go to the following link:

https://secure.shareit.com/shareit/checkout.html?PRODUCT[215982]=1&PRODUCTPRICE[215982]=239.00USD%2CN

The price there is 239.00. THIS is the number that needs to be changed

depending on the total price calculated for the customer.

For paypal, the link is:

https://www.paypal.com/xclick/business=support%40cyberleader.net&item_name=CyberLeader+Software+%28Lifetime+License%29&amount=239.00&no_shipping=1&cn=Machine+ID&currency_code=USD

Here the number is 239.00 too. So here goes your number from the script.

Thats it

If you can help please replay

Big thanx
Copy linkTweet thisAlerts:
@jdorfJan 04.2005 — Part of your problem is here:
<i>
</i>function CalculatePrice(){
if (document.form1.pices.value = 5){


Your if statement is SETTING the value to 5 (=) as opposed to CHECKING to see if the value equals 5 (==)

switch this to
[code]
if (document.form1.pices.value == 5){
[code]

that would be a good start.


Also,

Get rid of the entire else statement in the Validate function. It is unnecessary.
Copy linkTweet thisAlerts:
@jdorfJan 04.2005 — Now, you've changed the way you're working it on the web page... but this is what you need if you're going to use the form as you mentioned above.:

<i>
</i>function Validate(){
if (document.form1.pices.value &lt;= 5){
document.form1.pices.value = 5;
}

}
function CalculatePrice(){
if (document.form1.pices.value == 5){
calculation = 100 + (document.form1.pices.value * 12);
}
if (document.form1.pices.value &gt;= 6 &amp;&amp; document.form1.pices.value &lt;= 10){
calculation = 100 + (document.form1.pices.value * 10);
}
if (document.form1.pices.value &gt; 10){
calculation = 100 + (document.form1.pices.value * 8);
}
document.form1.result.value = calculation;
}
Copy linkTweet thisAlerts:
@jvsonicauthorJan 04.2005 — Hy thanx fotr this part i have the same code but the next step is important so if you know haw to do it please
Copy linkTweet thisAlerts:
@jdorfJan 04.2005 — Just make the page into two separate forms...

form1 is the form which accepts the number of clients in a text field (as is)

form2 is the form which is submitted...

then you can make this line:

document.form1.result.value = calculation;

into this line instead (or simply ADD that line so that the final value shows up in two places):

document.form2.amount.value = calculation;
×

Success!

Help @jvsonic 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.8,
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,
)...