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

reading a value from a dropdown box on a form

hi

I am trying to work out if i can read a value from a dropdown box to
caculate a running total on selection of a form

I using romancart as way to get the data to the form but wish to have a
simple total on screen so when user change the option / upgrade it displays
the value on screen before posting the form

i have done very little javascript so pls if you could explain or least show
some rough code example that would be appreciated

here my code so far

<SCRIPT LANGUAGE="JavaScript">
function alerter() {
alert(itemname3)
}
<form action=http://www.romancart.com/cart.asp name="myform">
<input type=hidden name=displaycart value=no>
<input type=hidden name=storeid value=10000>

<select name=itemname3 size="1"
onchange="alerter(document.myform.itemname3)">
<option value="2800 {10.00}">2800 AMD 64</option>
<option value="3000 {20.00}">3000 AMD 64</option>
<option value="3200 {30.00}">3200 AMD 64</option>
<option value="3400 {40.00}">3400 AMD 64</option>
<option value="3700 {50.00}">3700 AMD 64</option>
</select>

i understand i would need to parse the value to get the number inside the
curly brackets but i really not too sure of what i am doing.

can someone give me some ideas of where i going wrong ...

thanks
Jul 23 '05 #1
9 5530
Nick Calladine wrote:
hi

I am trying to work out if i can read a value from a dropdown box to
caculate a running total on selection of a form

I using romancart as way to get the data to the form but wish to have a
simple total on screen so when user change the option / upgrade it displays
the value on screen before posting the form

i have done very little javascript so pls if you could explain or least show
some rough code example that would be appreciated

here my code so far

<SCRIPT LANGUAGE="JavaScript">
function alerter() {
alert(itemname3)
}
<form action=http://www.romancart.com/cart.asp name="myform">
<input type=hidden name=displaycart value=no>
<input type=hidden name=storeid value=10000>

<select name=itemname3 size="1"
onchange="alerter(document.myform.itemname3)">
<option value="2800 {10.00}">2800 AMD 64</option>
<option value="3000 {20.00}">3000 AMD 64</option>
<option value="3200 {30.00}">3200 AMD 64</option>
<option value="3400 {40.00}">3400 AMD 64</option>
<option value="3700 {50.00}">3700 AMD 64</option>
</select>

i understand i would need to parse the value to get the number inside the
curly brackets but i really not too sure of what i am doing.

can someone give me some ideas of where i going wrong ...

onchange=
"alert(parseFloat(this[this.selectedIndex].value.split('{')[1],10))">

Mick
Jul 23 '05 #2
Thanks mick for the fast response....
easy when u know how..

is there a way that i can get the value within the brackets
ie. 10.00 and 20.00 and store it as a numeric / currency easily or will i
have to go and loop through the return value to manual get what's is between
the { } and then convert it to a numeric value

thanks once again

Nick

"Mick White" <mw***********@rochester.rr.com> wrote in message
news:WH******************@twister.nyroc.rr.com...
Nick Calladine wrote:
hi

I am trying to work out if i can read a value from a dropdown box to
caculate a running total on selection of a form

I using romancart as way to get the data to the form but wish to have a
simple total on screen so when user change the option / upgrade it
displays the value on screen before posting the form

i have done very little javascript so pls if you could explain or least
show some rough code example that would be appreciated

here my code so far

<SCRIPT LANGUAGE="JavaScript">
function alerter() {
alert(itemname3)
}
<form action=http://www.romancart.com/cart.asp name="myform">
<input type=hidden name=displaycart value=no>
<input type=hidden name=storeid value=10000>

<select name=itemname3 size="1"
onchange="alerter(document.myform.itemname3)">
<option value="2800 {10.00}">2800 AMD 64</option>
<option value="3000 {20.00}">3000 AMD 64</option>
<option value="3200 {30.00}">3200 AMD 64</option>
<option value="3400 {40.00}">3400 AMD 64</option>
<option value="3700 {50.00}">3700 AMD 64</option>
</select>

i understand i would need to parse the value to get the number inside the
curly brackets but i really not too sure of what i am doing.

can someone give me some ideas of where i going wrong ...

onchange=
"alert(parseFloat(this[this.selectedIndex].value.split('{')[1],10))">

Mick

Jul 23 '05 #3
Nick Calladine wrote:
Thanks mick for the fast response....
easy when u know how..

is there a way that i can get the value within the brackets
ie. 10.00 and 20.00 and store it as a numeric / currency easily or will i
have to go and loop through the return value to manual get what's is between
the { } and then convert it to a numeric value


Please don't top-post. Reply just below a trimmed quote of what you
are replying to.

You can use a regular expression to get the stuff inside the
braces:

function getCash(x){
var y = x.replace(/^.*\{|\}/g,'');
alert(y);
}

getCash( '2800 {10.00}' );
'y' will be string, to convert it to a number, either use
parseFloat() or the unary '+' operator:

var y = parseFloat( x.replace(/^.*\{|\}/g,'') );

or

var y = +x.replace(/^.*\{|\}/g,'');

The '+' must appear immediately before 'x' with no whitespace.
Converting y to a number will cause the decimal places to disappear
(if y is an integer like 10.00), but you can use toFixed() to display
2 decimal places in output:

alert( y ); // --> 10
alert( y.toFixed(2) ); // --> 10.00

Usually formatting is only applied for output intended for human
consumption (unless we're talking COBOL or fixed-length records...).

--
Rob
Jul 23 '05 #4
getcash(2300 {10.05});
function getCash(x){
var y = x.replace(/^.*\{|\}/g,'');
alert(y);


Hi Rob

can you please explain how it get the information from the bracket from the
replace function as i cant see how it works.. ?
it just doesnt make any sense...

Nick
Jul 23 '05 #5
Nick Calladine wrote:
Thanks mick for the fast response....
easy when u know how..

is there a way that i can get the value within the brackets
ie. 10.00 and 20.00 and store it as a numeric / currency easily or will i
have to go and loop through the return value to manual get what's is between
the { } and then convert it to a numeric value


onchange= alert("$"+
this[this.selectedIndex].value.split('{')[1].replace(/[^\d.]/g,"")))

Mick.
Jul 23 '05 #6
> onchange= alert("$"+
this[this.selectedIndex].value.split('{')[1].replace(/[^\d.]/g,"")))

Mick.


can you please explain how it get the information from the bracket from the
replace function as i cant see how it works.. ?
it just doesnt make any sense...

Nick
Jul 23 '05 #7
Nick Calladine wrote:
onchange= alert("$"+
this[this.selectedIndex].value.split('{')[1].replace(/[^\d.]/g,"")))

Mick.

can you please explain how it get the information from the bracket from the
replace function as i cant see how it works.. ?
it just doesnt make any sense...

<select name=itemname3 size="1"
onchange="alert("$"+
this[this.selectedIndex].value.split('{')[1].replace(/[^\d.]/g,"")))"

<option value="2800 {10.00}">2800 AMD 64</option>
<option value="3000 {20.00}">3000 AMD 64</option>
<option value="3200 {30.00}">3200 AMD 64</option>
<option value="3400 {40.00}">3400 AMD 64</option>
<option value="3700 {50.00}">3700 AMD 64</option>
</select>

Let's say you select the second option

this[this.selectedIndex].value == "3000 {20.00}"

"3000 {20.00}".split('{')[1] == "20.00}"
//create an array from string, the divider being "{", the second entry
("[1]") of the array="20.00}"

"20.00}".replace(/[^\d.]/g,"") == "20.00"
// remove anything that is not a digit or a dot.

alert("$"+"20.00") == $20.00

Mick


Jul 23 '05 #8
Mick

thanks for your help it is most appreciated

thanks
a very gratefull and slow learner

Nick
Jul 23 '05 #9
JRS: In article <42aed23f$0$22907$5a62ac22@per-qv1-newsreader-
01.iinet.net.au>, dated Tue, 14 Jun 2005 22:49:12, seen in
news:comp.lang.javascript, RobG <rg***@iinet.net.auau> posted :
or the unary '+' operator: The '+' must appear immediately before 'x' with no whitespace.


Which browsers require absence of whitespace?

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
<URL:http://www.jibbering.com/faq/> JL/RC: FAQ of news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Jul 23 '05 #10

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

Similar topics

0
by: Mamun | last post by:
Hi All, I have the following case. I am trying to update a table based on the value of dropdown box and checkbox. Here is what I have in page1.asp <table>
24
by: London | last post by:
Hello Can you help me. By ASP How can I get the dropdown(control'name)'s selected value? What is it's property'name?
4
by: Lisa | last post by:
I know this is supposed to be easy but I can't get this to work. I have a dropdown that pulls all the Projects (tp_title) available. All I want to do is get the ID (tp_id) of that record so I can...
8
by: Lyn | last post by:
Hi, Can anyone tell me how the initial value displayed in Combo Box is determined when a form is opened? I am loading the dropdown from one field ("CategoryName") of a table, with "ORDER BY ". ...
1
by: Mad Scientist Jr | last post by:
I don't know how this is happening, but a dropdown control I have is resetting to the 2nd value on the list anytime a postback occurs. I have no initiation code outside of If Not (IsPostBack) ...
6
by: | last post by:
Do you have to use AutoPostBack to read the selected value in a dropdown list? I have an asp.net dropdown on a form. I'm filling it from a table when the page loads and want to read the value the...
2
by: Mike Collins | last post by:
I cannot get the correct drop down list value from a drop down I have on my web form. I get the initial value that was loaded in the list. It was asked by someone else what the autopostback was...
2
by: Bruno Alexandre | last post by:
Hi guys, I'm using Javascript to dynamically add to a dropdown values like for ( i=0; i<tv.length; i++ ) { selectDDAvisCtrl.options = new Option(tv, tv); } and I use ...
1
by: deepaks85 | last post by:
Dear Friends, I have create a form in which user can update his/her records. The data can retrieved from the code which i have put in dropdown menu. Now I want to display all the records as per...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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.