INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

How to implement an automatic JS-multiplication in a combo box

How to implement an automatic JS-multiplication in a combo box

How to implement an automatic JS-multiplication in a combo box

(OP)
In a MS Access table i will update the following two fields :
=> an input field called NUMBER => to fill in a selection (=number) from a list box (see below)
=> a field called AMOUNT in which automatically (the entered NUMBER * x) is (should be) calculated => the result should be displayed in this AMOUNT-field

My tryouts did not work.
Is it possible to use Javascript in my code ?
Thanks for tips - Leifoet


My code
.....
<tr>
<td><b>Number_2016<b></b></td>
<td width="353">

<SELECT name="Number_2016" style="font-size:13px; color:#0000FF; text-align:right; background-color:#E0FFFF;">
<OPTION SELECTED value="<%=rsTEST("team1")%>" style="font-family:arial,sans-serif;font-size:12px;font-weight:bold;
font-size:12px; color:#0000FF; text-align:left; background-color:#FFFAFA;"><%=rsTEST("Number_2016")%></option>
<option value=0 style="font-family:arial,sans-serif;font-size:12px; color:#FF1616;">0</option>
<option value=1 style="font-family:arial,sans-serif;font-size:12px; color:#0000FF;">1</option>
<option value=2 style="font-family:arial,sans-serif;font-size:12px; color:#0000FF;">2</option>
<option value=3 style="font-family:arial,sans-serif;font-size:12px; color:#0000FF;">3</option>
.... up to 100

[indent</select><br>
</td></tr>

<tr>
<td height="26"><b>Amount_2016</b></td>
<td height="26" width="353">
<INPUT TYPE="number" size="12" value="<%=rsFOCOTEST("Amount_2016")%>" NAME="Amount" onFocus="blur()" style="font-weight:bold; font-family:arial,sans-serif;
font-size:12px; color:#0000FF; text-align:right;"><font size="1" color="black">&nbsp;&nbsp;&nbsp;(niet wijzigen)</td>

</tr>

RE: How to implement an automatic JS-multiplication in a combo box

You could use the onChange event of the select element to pass the selected option value to your calculate function.


onChange="calculateFunction(this.selectedIndex.value)"

Or if you want the values to update as the document loads you can use the body onLoad event.

calculateFunction(document.getElementById("SelectID").value)

Chris.

Indifference will be the downfall of mankind, but who cares?
Time flies like an arrow, however, fruit flies like a banana.
Webmaster Forum

RE: How to implement an automatic JS-multiplication in a combo box

(OP)
As I understand it, I write in the body (input Number field): onChange="calculateFunction(this.selectedIndex.value)"
Sorry for my two further problems (I am only a hobby 'programmer' for my sports club)
=> what is also the Java-code to be written in the head ?
=> can I become the output of this calculation directly in the Amount-(input)field of the form (as mentioned in my initial question above)?

Thanks for (a bit more) details - Leifoet

RE: How to implement an automatic JS-multiplication in a combo box

Quote:

Java-code

javascript (little 'j') code, as Java (capital 'J') code is a whole different language with syntax similarities



The calculateFunction script which may or may not be defined in the <head> section of the document is the multiplication code, which is at it's simplest;

CODE --> javascript

<script type="text/javascript">
function calculateFunction(p_iMult) {
document.getElementById('amount').value = document.getElementById('number').value * p_iMult;
}
</script> 
You do of course have to add the necessary ID attributes to you form elements, and call the function from the onBlur event of the 'number' input element so the calculateFunction runs when the element loses focus.

Chris.

Indifference will be the downfall of mankind, but who cares?
Time flies like an arrow, however, fruit flies like a banana.
Webmaster Forum

RE: How to implement an automatic JS-multiplication in a combo box

(OP)
Preliminary final question in my javascript matter (amount = number * p_iMult) => where comes the exact value (=75) for this p_iMult in the script ?

<script type="text/javascript">
function calculateFunction(p_iMult) {
document.getElementById('amount').value = document.getElementById('number').value * p_iMult;
}
</script>

Thanks - Leifoet

RE: How to implement an automatic JS-multiplication in a combo box


Quote:

where comes the exact value (=75) for this p_iMult in the script


function calculateFunction(p_iMult)

from here ..................^^^^^^

you pass it as a parameter when you call the function, as you can see in the earlier examples:

onChange="calculateFunction(this.selectedIndex.value)"

..............................^^^^^^^^^^^^^^^^^^^^^..... becomes p_iMult in the function

http://www.w3schools.com/js/js_functions.asp

the p_i... is just my variable naming method

"p_" indicates it is a passed parameter

"i" indicates it is a integer

so "p_i" means it a an integer value passed as a parameter to the function.

Chris.

Indifference will be the downfall of mankind, but who cares?
Time flies like an arrow, however, fruit flies like a banana.
Webmaster Forum

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close