I'm having trouble creating a very simple running total of a
few drop down list. I have three seperate dropdown lists, I
want the user to simply select some numbers and have the
total of the selected numbers displayed.
I'm not much of a programmer and this is really just a
experiment. Can anyone help me out here. I know the code
below doesnt work (no form tags etx0 but I thought the logic
was fine?
Example of what I would like to happen
User selects 2,5,6 and a total of 13 is displayed somewhere
on the page. This total changes when the user picks
different numbers.
Can anyone help me out here?
------------------------------------------------------------
--------
Code
</head>
<script language="javas cript">
function workit()
{
var itemA=document. select.value
var itemB=document. select2.value
var itemC=document. select3.value
var total = itemA+itemB+ite mC;
}
</script>
<body>
<p>
<select name="select" onChange="worki t()">
<option value="1" selected>One</option>
<option value="2">Two</option>
<option value="3">Three </option>
</select>
<select name="select2" onChange="worki t()">
<option value="4" selected>Four</option>
<option value="5">Five</option>
<option value="6">Six</option>
</select>
<select name="select3" onChange="worki t()">
<option value="7" selected>Seven</option>
<option value="8">Eight </option>
<option value="9">Nine</option>
</select>
</p>
<p><span id=mytotal></span></p>
</body>
</html> 5 3589
I've been picking up javascript these past six months - I think my
single line below should do what you want to do, though you might find
one or two others who might correct my methods... </head> <script language="javas cript"> function workit() { var itemA=document. select.value var itemB=document. select2.value var itemC=document. select3.value var total = itemA+itemB+ite mC;
document.getEle mentById('mytot al').innerHTML= total; } </script> <body> <p> <select name="select" onChange="worki t()"> <option value="1" selected>One</option> <option value="2">Two</option> <option value="3">Three </option> </select> <select name="select2" onChange="worki t()"> <option value="4" selected>Four</option> <option value="5">Five</option> <option value="6">Six</option> </select> <select name="select3" onChange="worki t()"> <option value="7" selected>Seven</option> <option value="8">Eight </option> <option value="9">Nine</option> </select> </p> <p><span id=mytotal></span></p> </body> </html>
Hope I've helped,
randelld
Reply Via Newsgroup wrote: I've been picking up javascript these past six months - I
think my single line below should do what you want to do, though
you might find one or two others who might correct my methods...
thanks m8, I will give it a go.
"Cheddar" <my************ *@dsl.pipex.com > a écrit dans le message de
news:c5******** ****@ID-179732.news.uni-berlin.de... I'm having trouble creating a very simple running total of a few drop down list. I have three seperate dropdown lists, I want the user to simply select some numbers and have the total of the selected numbers displayed.
I'm not much of a programmer and this is really just a experiment. Can anyone help me out here. I know the code below doesnt work (no form tags etx0 but I thought the logic was fine?
Example of what I would like to happen
User selects 2,5,6 and a total of 13 is displayed somewhere on the page. This total changes when the user picks different numbers.
Can anyone help me out here?
------------------------------------------------------------ -------- Code
</head> <script language="javas cript"> function workit() { var itemA=document. select.value var itemB=document. select2.value var itemC=document. select3.value var total = itemA+itemB+ite mC;
Try this instead:
function workit()
{
var itemA = parseInt(select .options[select.selected Index].value);
var itemB = parseInt(select 2.options[select2.selecte dIndex].value);
var itemC = parseInt(select 3.options[select3.selecte dIndex].value);
var total = itemA + itemB + itemC;
mytotal.innerHT ML = total;
}
} </script> <body> <p> <select name="select" onChange="worki t()"> <option value="1" selected>One</option> <option value="2">Two</option> <option value="3">Three </option> </select> <select name="select2" onChange="worki t()"> <option value="4" selected>Four</option> <option value="5">Five</option> <option value="6">Six</option> </select> <select name="select3" onChange="worki t()"> <option value="7" selected>Seven</option> <option value="8">Eight </option> <option value="9">Nine</option> </select> </p> <p><span id=mytotal></span></p> </body> </html>
Morris wrote: Try this instead: function workit() { var itemA =
parseInt(select .options[select.selected Index].value); var itemB =
parseInt(select 2.options[select2.selecte dIndex].value); var
itemC = parseInt(select 3.options[select3.selecte dIndex].value);
var total = itemA + itemB + itemC; mytotal.innerHT ML = total; }
Good stuff, thanks a lot.
JRS: In article <0k************ ********@wagner .videotron.net> , seen in
news:comp.lang. javascript, Morris <mo********@eud oramail.com> posted at
Wed, 14 Apr 2004 17:47:39 : Try this instead: function workit() { var itemA = parseInt(select .options[select.selected Index].value);
But only after considering whether the string .value might have a
leading zero, and what (a) might happen, (b) is needed, in that case.
Read the FAQ.
--
© John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 IE 4 ©
<URL:http://jibbering.com/faq/> Jim Ley's FAQ for news:comp.lang. javascript
<URL:http://www.merlyn.demo n.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demo n.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Quinn |
last post by:
HI!
Have two from text fields named "odds" and "stake" where I enter numeric
values.
I want to have a text label named "returns" that is automatically updated
whenever any of these changes.
Here's my first try (I have cut this out from the form, named form_bet):
<input name="odds" type="text" id="odds" onChange="updateReturns();"
|
by: daveland |
last post by:
I am working on some JavaScript that dynamically adds rows to a table
in response to a button click. A new row does appear on the screen
when the button is clicked. However, that table to which a row has
been added is itself contained within an outer table (to handle the
desired screen layout). That outer table does not properly grow to...
|
by: engwar |
last post by:
I'd like to know if it's possible to change the contents of a div tag
based on something the user is doing.
For example. If there is a text box on a page and the user types his or
her name can I update an existing div tag to show what they've typed
in?
Thanks.
|
by: Neo Geshel |
last post by:
Greetings.
I am in a very big pickle. I am trying to add page content - as well as
a submit button - programatically to a web form that is supposed to
submit to DB and then refresh.
That is, a user goes to the web page, which draws the current content
out of the db and inserts into a "preview" area as well as the form
itself. User...
|
by: darrel |
last post by:
I am using a javascript WYSIWYG text editor for our CMS. To grab the proper
content we need to add a javacsript call to the form:
Form1.Attributes.Add("onSubmit", "myOnSubmitEventHandler();")
That works fine.
However, we also have some dropDownLists that trigger a postback. If we
change these, I still need to update the text editor, so...
| |
by: mayan67 |
last post by:
I am trying to add sound, video and a rolling credit class applet. I have put in the information and nothing works. I am not sure what I have done wrong This is just a simple web page using some JavaScript.
Here is my code.
<html>
<head>
<title>Validation Form</title>
</head>
|
by: The Eclectic Electric |
last post by:
I'd be very grateful if anyone could help me with this. From my limited
knowledge of Javascript I don't think it is possible, but I'll punt anyway.
I downloaded and very slightly adapted this guy's Javascript "combo box" -
http://sandy.mcarthur.org/javascript/select/select.html. It allows my users
(when I get some!) to select from a list of...
|
by: eureka |
last post by:
Hi friends,
I am developing a web application using Jsp and JS.
I have a main Jsp page(Jsp1).Inside it I have an iframe having an Html-
table which is created dynamically and contains all records from the
backend-table . For creating this dynamic table I've used another
Jsp(Jsp2) and in Jsp1 I say:
<iframe id = "I1" src="Jsp2.jsp"...
|
by: ballygowanboy |
last post by:
i've put this code together.
there's a variable "s" giving me some grief at the mo, i'm actualy supprised it half works.
it's a simple shopping cart, you pick the quantitly of items, and it adds the total quantitly, total price including vat, that worked, now, that i've introduced shipping, i'm having a bit of trouble.
the shipping value...
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it. ...
|
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...
| |