473,394 Members | 1,766 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Simple calculation with one variable - Help needed

Hello!

I m new here and also not a programmer. But i try to write a little JS for a website..
This little script should be able to divide something. For this i wrote the following:

<script type="text/javascript language="JavaScript">
function compute() {
var divid = document.forms.divide.divident.value;
var operator = document.forms.operator.value;
document.forms.divide.quotient.value = divid / operator;
}

</script>
<form name=divide action="javascript:compute();">
<input type=text name=divident size=5 maxlength=5>
<select name="operator">
<option value="10">10 % </option>
<option value="15">15 % </option>
<option value="20">20 % </option>
</select>
<input type=text name=quotient size=6 maxlength=6>
<input type=submit value="Berechnen">
<input type=reset value=Reset>
</form>

... but it doesnt work. Whats wrong? Please help me to solve this.

Best regards

Chris
Mar 7 '07 #1
3 1226
acoder
16,027 Expert Mod 8TB
Welcome to The Scripts.

The problem is that you are trying to access 'operator' incorrectly. Try
Expand|Select|Wrap|Line Numbers
  1. var operator = document.forms.divide.operator.value;
You forgot the name of the form 'divide'.

PS: You could achieve the same functionality without a submit button, using a simple button and calling compute() in the onclick event handler.
Mar 7 '07 #2
Welcome to The Scripts.

The problem is that you are trying to access 'operator' incorrectly. Try
Expand|Select|Wrap|Line Numbers
  1. var operator = document.forms.divide.operator.value;
You forgot the name of the form 'divide'.

PS: You could achieve the same functionality without a submit button, using a simple button and calling compute() in the onclick event handler.
Hello acoder!

Thank yo very much, i tryed your solution and it works!
But now i realised that i have the wrong thinkings about what the script
should do :-(

It should to calculate a percentage of the "divident"

An example:

@ Divident (1st field) the user wrote 10000 and select 10 %...
the calculation must be result in 1000...

if the user wrote 10000 and choose 20% it results in 2000 and so on...

Whats my error in thinking? Would you so pleased and correct my code
that it works in the scheme above? And also i want to know what i must do that the user can only type numbers and no letters in the fields....
But.. im not a programmer... bad bad...

Thank you very much!

Best regards

Chris

<script type="text/javascript language="JavaScript">
function compute() {
var divid = document.forms.divide.divident.value;
var operator = document.forms.divide.operator.value;
document.forms.divide.quotient.value = divid / operator;
}

</script>
<form name=divide action="javascript:compute();">
<input type=text name=divident size=5 maxlength=5>
<select name="operator">
<option value="10">10 % </option>
<option value="15">15 % </option>
<option value="20">20 % </option>
</select>
<input type=text name=quotient size=6 maxlength=6>
<input type=submit value="Berechnen">
<input type=reset value=Reset>
</form>
Mar 7 '07 #3
acoder
16,027 Expert Mod 8TB
That's quite simple. Just change the values in the select box to "0.something", e.g. change 10 to 0.1, 20 to 0.2, etc.

Then change the division to a multiplication:
Expand|Select|Wrap|Line Numbers
  1. document.forms.divide.quotient.value = divid * operator;
Mar 7 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

17
by: savesdeday | last post by:
In my beginnning computer science class we were asked to translate a simple interest problem. We are expected to write an algorithm that gets values for the starting account balance B, annual...
0
by: anaxamandr | last post by:
Hi. I have a long loop in ASP that performs a rather lengthy calculation. I would love for my users to be able to stop that calculation, if they so choose, mid way through the process. I attempted...
2
by: Niyazi | last post by:
Hi everyone, I have a sql table that has 5 column as: cl1Month - cl1_3Month - cl3_6Month - cl6_12Month - clMoreThan12Month Now I have to date and I have to find the differences and check as...
6
by: David | last post by:
Hi, I have the following calculation I am trying to work out ..... Not sure how ? Variable 1 = minstock Variable 2 = oDict(oKey) I need to test if my variable 'minstock' <= 40% of...
4
by: SijSaru13 | last post by:
Dear everybody, I have to write a program that implements a real-time multicast calculator service. Users join a multicast group and are able to send equations to other clients for calculation -...
10
by: 60325 | last post by:
This is the page where I collect the data in drop-down boxes with values of 1-10 and send it to a submitted page to do calculations. Example: Employee1 TeamScore(1-10) Employee2 ...
1
by: c8tz | last post by:
This is a query I have created that picks up the top 3 dates for this data (for example) : Tree Pos2 Date 1 15 23/08/2005 1 20 12/02/2006 1 32 15/10/2006 ...
19
by: LucasLondon | last post by:
Hi there, First of all apologies for the long post. Hope someone can offer some advice. I have about 200 columns of time series data that I need to perform a correlation analysis on in terms...
4
by: TonyJ | last post by:
Hello! Assume I have the two classes Test1 and Test2. They are very similar. Test1 initialize the instance variable in the C-tor but Test2 initialize the instance variable without using the...
1
by: csolomon | last post by:
I have an unbound text box which I use to get a calculation, called DM_SampleWt. This text box's control source is: =GetSize(,Nz(,0),.!,.!.(2)) I have written a function that will get the required...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.