473,385 Members | 1,732 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,385 software developers and data experts.

I thought this would be easy - HELP

EJ
var theSel = document.forms['price'].elements['cpu'];
var theVal = theSel.options[theSel.selectedIndex].value;
var theSli = theVal.slice(1,3);
this doen't seem to work

var cpus = document.forms['price'].elements['cpu'];
var cpusx = cpus.options[cpus.selectedIndex].value;
var cpusxd = cpusx.slice(8,10);

when I use the event handler

onchange="document.forms['price'].value=cost(cpusxd,shpsxd)"

I get the error message: "cpudsx undefined

Mar 24 '07 #1
7 1637
"EJ" <jo********@hotmail.comwrote in news:1174703621.570832.232670
@o5g2000hsb.googlegroups.com:
>var theSel = document.forms['price'].elements['cpu'];
var theVal = theSel.options[theSel.selectedIndex].value;
var theSli = theVal.slice(1,3);

this doen't seem to work

var cpus = document.forms['price'].elements['cpu'];
var cpusx = cpus.options[cpus.selectedIndex].value;
var cpusxd = cpusx.slice(8,10);

when I use the event handler

onchange="document.forms['price'].value=cost(cpusxd,shpsxd)"

I get the error message: "cpudsx undefined

Check your spelling: ( cpusxd vs. cpudsx ) One of the limitations of
variable names you can't pronounce.

Also, your onchange code lacks any mention of which element in the form
you want to change the value.
Mar 24 '07 #2
"EJ" <jo********@hotmail.comwrote in news:1174703621.570832.232670
@o5g2000hsb.googlegroups.com:
>var theSel = document.forms['price'].elements['cpu'];
var theVal = theSel.options[theSel.selectedIndex].value;
var theSli = theVal.slice(1,3);

this doen't seem to work

var cpus = document.forms['price'].elements['cpu'];
var cpusx = cpus.options[cpus.selectedIndex].value;
var cpusxd = cpusx.slice(8,10);

when I use the event handler

onchange="document.forms['price'].value=cost(cpusxd,shpsxd)"

I get the error message: "cpudsx undefined

Put everything in a function. The variables cpus, cpusx, cpusxd must be
evaluated after the onchange event happens.

function myFunc = {
var cpus = document.forms['price'].elements['cpu'];
var cpusx = cpus.options[cpus.selectedIndex].value;
var cpusxd = cpusx.slice(8,10);
document.forms['price'].elements['something'].value=cost(cpusxd,shpsxd)
}

onchange = "myFunc();"
Mar 24 '07 #3
EJ
On Mar 24, 1:10 am, Jim Land <rrrrfffftttt(no)@(spam)hotmail.com>
wrote:
"EJ" <jordane...@hotmail.comwrote in news:1174703621.570832.232670
@o5g2000hsb.googlegroups.com:
Put everything in a function. The variables cpus, cpusx, cpusxd must be
evaluated after the onchange event happens.
thanks, but why?

also you wrote:
Are you trying to insert the sum into the hidden element?
document.forms['price'].elements['amount'],value = cpusxd + shpsxd;
this does not produce a sum, or rather the following function does not
produce a sum

function total()
{
var cpus = document.forms['price'].elements['cpu'];
var cpusx = cpus.options[cpus.selectedIndex].value;
var cpusxd = cpusx.slice(6);
var shps = document.forms['price'].elements['shp'];
var shpsx = shps.options[shps.selectedIndex].value;
var shpsxd = shpsx.slice(7);
document.forms['price'].elements['amount'].value = cpusxd + shpsxd;
}

please note:

<select name="cpu" id="cpu" onchange="total();">
<option selected value="AMDx - 2500">

<select name="shp" id="shp" onchange="total();">
<option selected value="3Day - 100">

....
onchange="total();"returns 2500100

Mar 25 '07 #4
"EJ" <jo********@hotmail.comwrote in news:1174794390.053055.114290
@y66g2000hsf.googlegroups.com:
document.forms['price'].elements['amount'].value = cpusxd + shpsxd;
Sorry. This should work:

document.forms['price'].elements['amount'].value = +cpusxd + shpsxd;

The + in front of cpusxd converts from string to number.
Mar 25 '07 #5
In comp.lang.javascript message <Xns98FDF13CA7CB7rrrrffffttttnospamho@21
6.168.3.44>, Sun, 25 Mar 2007 04:42:52, Jim Land
<rr**********@hotmail.composted:
>"EJ" <jo********@hotmail.comwrote in news:1174794390.053055.114290
@y66g2000hsf.googlegroups.com:
> document.forms['price'].elements['amount'].value = cpusxd + shpsxd;

Sorry. This should work:

document.forms['price'].elements['amount'].value = +cpusxd + shpsxd;

The + in front of cpusxd converts from string to number.
You need to test not only your code but also your "corrections".

That should be ... = +cpusxd + +shpsxd; since + between Number and
String converts the Number to String and concatenates.

It's a good idea to read the newsgroup c.l.j and its FAQ. See below.

--
(c) John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v6.05 IE 6
news:comp.lang.javascript FAQ <URL:http://www.jibbering.com/faq/index.html>.
<URL:http://www.merlyn.demon.co.uk/js-index.htmjscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/TP/BP/Delphi/jscr/&c, FAQ items, links.
Mar 26 '07 #6
Dr J R Stockton <jr*@merlyn.demon.co.ukwrote in news:Uh74ap4FA
$B*****@invalid.uk.co.demon.merlyn.invalid:
That should be ... = +cpusxd + +shpsxd; since + between Number and
String converts the Number to String and concatenates.
I stand corrected.
Mar 27 '07 #7
EJ
thanks, you have all been a great help

Mar 28 '07 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Ron Adam | last post by:
With all the discussion about numbers here and particularly in regards to prePEP concerning decimal data types got me wondering about how numbers are handled when it comes to rounding. And if that...
24
by: Charif Lakchiri | last post by:
Okay, here's what I know so far about Python: It's an object-oriented scripting language, supported on many platforms. Now here are my questions: It is easy to learn? Does it support GUI...
116
by: Mike MacSween | last post by:
S**t for brains strikes again! Why did I do that? When I met the clients and at some point they vaguely asked whether eventually would it be possible to have some people who could read the data...
5
by: tHeRoBeRtMiTcHeLL | last post by:
Well, I think I have bitten off a little more than I can chew (at least all at once), and I'm only trying to hammer out tables/relationships at the design level. Which translates to "Seasoned...
22
by: Charles Law | last post by:
Could someone please explain to me, in words of one syllable or less, how I get the Validating event to fire for a form. I have a form with one text box, and two buttons: OK and Cancel. I have...
4
by: Michael | last post by:
Hi, I'm having difficulty finding any previous discussion on this -- I keep finding people either having problems calling os.exec(lepev), or with using python's exec statement. Neither of...
9
by: JT | last post by:
Here is the overall structure I will be referring to: End-program ProvideWorkFlow.dll Forms and methods that properly manipulate calls to methods in AccessUtils AccessUtils (a web service)...
111
by: Enteng | last post by:
Hi I'm thinking about learning C as my first programming language. Would you recommend it? Also how do you suggest that I learn it?What books/tutorials should I read for someone like me? Thanks...
14
by: EJ | last post by:
I'm real new to javasscript. The task is to develop a web page which will allow users to customize a laptop ... show the price as they change options ... transfer the price and system description...
1
by: blangela | last post by:
I apologize for being somewhat off topic, but I cannot resist making this post. One of my less gifted students submitted a better solution for the tictactoe problem I had assigned than I...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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...

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.