close ad
Install the LAtest Updates to Work with CC 2017 and CC 2018
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

How to get Value of select menu ?

Thread began 4/28/2010 1:01 pm by Fritz Stickers | Last modified 5/02/2010 6:56 am by Fritz Stickers | 1859 views | 13 replies |

Fritz Stickers

How to get Value of select menu ?

How can I get the value of a select menu (form name = FrogStyling_1_Size_Add) ?
The select menu has the choice of a few sizes :
size 10 = € -1,00
size 15 = € = 4,00 <!--(rsDetail.Fields.Item("ProductPrice").Value) : initially selected-->
size 20 = € +2,00
size 25 = € +4,00
size 30 = € +6,00
size 35 = € +8,00

The standard price is shown. I want the price show to what the customer selected.
I had this to begin, but get this : error 'ASP 0102 : 80004005' :

<% If Request.Form(FrogStyling_1_Size_Add)=10 Then
Response.Write(FormatNumber(((rsDetail.Fields.Item("ProductPrice").Value)-1), 2, -2, -2, -2))
Else
Response.Write(FormatNumber(((rsDetail.Fields.Item("ProductPrice").Value)+5), 2, -2, -2, -2))
End If %>



My site is in ASP VBscript.

Sign in to reply to this post

Jason ByrnesWebAssist

you could do this using javascript on the onchange event of the select list, here is a small example:

price: $<span id="price">13</span>
<br />
<form id="form1" name="form1" method="post" action="">
Price List'
<select name="priceList" id="priceList" onChange="document.getElementById('price').innerHTML = document.form1.priceList[document.form1.priceList.selectedIndex].value">
<option value="12">Item 1 - $12</option>
<option value="13" selected="selected">Item 2 - $13</option>
<option value="14">item 3 - $14</option>
</select>
</form>
Sign in to reply to this post

Fritz Stickers

Thanks !
It works but the option values are needed in the eCart to calculate the price, which depends on the choosen size. So I can't change them like in your model.

<select name="FrogStyling_1_Size_Add" id="FrogStyling_1_Size_Add"  class="textfieldReg" onchange="document.getElementById('cmPrice').innerHTML = document.FrogStyling_1_ATC_<%=rsDetail.Fields("ProductID").value%>.FrogStyling_1_Size_Add[document.FrogStyling_1_ATC_<%=rsDetail.Fields("ProductID").value%>.FrogStyling_1_Size_Add.selectedIndex].value" >
<option value="10">10 cm - &euro; 1,00</option>
<option value="15" selected="selected">15 cm</option>
<option value="20">20 cm + &euro; 2,00</option>
<option value="25">25 cm + &euro; 4,00</option>
<option value="30">30 cm + &euro; 5,00</option>
<option value="35">35 cm + &euro; 6,00</option>
<option value="40">40 cm + &euro; 7,00</option>
<option value="45">45 cm + &euro; 8,00</option>
<option value="50">50 cm + &euro; 9,00</option>
<option value="55">55 cm + &euro; 10,00</option>
</select>


Isn't it possible to change the .value of the onchange event with a conditional statement ?

Sign in to reply to this post

Jason ByrnesWebAssist

sure, you could create a function to look up the price

<script type="text/javascript">
function getPrice(option) {
var thePrice;
switch (option) {
case '10':
thePrice = '1,00';
break;
case '15':
thePrice = '2,00';
break;
case '20':
thePrice = '3,00';
break;
case '25':
thePrice = '4,00';
break;
case '30':
thePrice = '5,00';
break;
case '35':
thePrice = '6,00';
break;
case '40':
thePrice = '7,00';
break;
case '45':
thePrice = '8,00';
break;
case '50':
thePrice = '9,00';
break;
case '55':
thePrice = '10,00';
break;
default:
thePrice = '2,00';
}
return thePrice;
}
</script>



the change the onchange script to:

onchange="document.getElementById('cmPrice').innerHTML = getPrice(document.FrogStyling_1_ATC_<%=rsDetail.Fields("ProductID").value%>.FrogStyling_1_Size_Add[document.FrogStyling_1_ATC_<%=rsDetail.Fields("ProductID").value%>.FrogStyling_1_Size_Add.selectedIndex].value)"
Sign in to reply to this post

Fritz Stickers

This also works. :) But thePrice is supposed to add 2, 4, 5, 6, ... to (rsDetail.Fields.Item("ProductPrice").Value).
I tried to change it, but it gives "NaN" back.
I hope you understand what I mean with the "var prodPrice" ?


<script type="text/javascript">
function getPrice(option) {
var prodPrice = document.getElementById("cmPrice").innerHTML
var thePrice;
switch (option) {
case '10':
thePrice = (prodPrice)-1;
break;
case '15':
thePrice = (rsDetail.Fields.Item("ProductPrice").Value);
break;
case '20':
thePrice = (prodPrice)+2;
break;
case '25':
thePrice = (prodPrice)+4;
break;
case '30':
thePrice = (prodPrice)+5;
break;
case '35':
thePrice =(prodPrice)+6;
break;
case '40':
thePrice = (prodPrice)+7;
break;
case '45':
thePrice = (prodPrice)+8;
break;
case '50':
thePrice = (prodPrice)+9;
break;
case '55':
thePrice = (prodPrice)+10;
break;
default:
thePrice = (rsDetail.Fields.Item("ProductPrice").Value);
}
return thePrice;
}
</script>
Sign in to reply to this post

Jason ByrnesWebAssist

please send your page in a zip archive so i can see the code in context.

Sign in to reply to this post

Fritz Stickers

See attach "Geert".

Attached Files
Geert.zip
Sign in to reply to this post

Jason ByrnesWebAssist

ok, do it this way instead. pass the price as another var in the onchange event:

onchange="document.getElementById('cmPrice').innerHTML = getPrice(document.FrogStyling_1_ATC_<%=rsDetail.Fields("ProductID").value%>.FrogStyling_1_Size_Add[document.FrogStyling_1_ATC_<%=rsDetail.Fields("ProductID").value%>.FrogStyling_1_Size_Add.selectedIndex].value, <%= FormatNumber((rsDetail.Fields.Item("ProductPrice").Value), 2, -2, -2, -2) %>)"




and change the function to take the extra param:

<script type="text/javascript">
function getPrice(option, prodPrice) {
var thePrice;
switch (option) {
case '10':
thePrice = prodPrice-1;
break;
case '15':
thePrice = prodPrice;
break;
case '20':
thePrice = prodPrice+2;
break;
case '25':
thePrice = prodPrice+3;
break;
case '30':
thePrice = prodPrice+4;
break;
case '35':
thePrice = prodPrice+5;
break;
case '40':
thePrice = prodPrice+6;
break;
case '45':
thePrice = prodPrice+7;
break;
case '50':
thePrice = prodPrice+8;
break;
case '55':
thePrice = prodPrice+9;
break;
default:
thePrice = prodPrice+10;
}
return thePrice;
}
</script>
Sign in to reply to this post

Fritz Stickers

That's working fine, but prices with 2 decimals are not showing right.
e.g.: 4,25 + 2 = 6 ... must be 6,25
I tried a lot of stuff, like Math.Round, toFixed(), ... in vain.

Is this one necessary :
default:
thePrice = prodPrice;

How works "prodPrice", is it a variable ?

Sign in to reply to this post

Jason ByrnesWebAssist

it's because the number is being passed using the comma as a decimal separator, javascript does not recognize the comma as a decimal separator


try this function instead, it will convert the comma to a period:

<script type="text/javascript">
function getPrice(option, prodPrice) {
var prodPrice = prodPrice.replace(",",".");
var thePrice;
switch (option) {
case '10':
thePrice = parseFloat(prodPrice)-1;
break;
case '15':
thePrice = parseFloat(prodPrice);
break;
case '20':
thePrice = parseFloat(prodPrice)+2;
break;
case '25':
thePrice = parseFloat(prodPrice)+3;
break;
case '30':
thePrice = parseFloat(prodPrice)+4;
break;
case '35':
thePrice = parseFloat(prodPrice)+5;
break;
case '40':
thePrice = parseFloat(prodPrice)+6;
break;
case '45':
thePrice = parseFloat(prodPrice)+7;
break;
case '50':
thePrice = parseFloat(prodPrice)+8;
break;
case '55':
thePrice = parseFloat(prodPrice)+9;
break;
default:
thePrice = parseFloat(prodPrice)+10;
}
return thePrice;
}
</script>




also in the onchange event, there needs to be single quotes around the price that is being passed:

onchange="document.getElementById('cmPrice').innerHTML = getPrice(document.FrogStyling_1_ATC_<%=rsDetail.Fields("ProductID").value%>.FrogStyling_1_Size_Add[document.FrogStyling_1_ATC_<%=rsDetail.Fields("ProductID").value%>.FrogStyling_1_Size_Add.selectedIndex].value, '<%= FormatNumber((rsDetail.Fields.Item("ProductPrice").Value), 2, -2, -2, -2) %>')"
Sign in to reply to this post
loading

Build websites with a little help from your friends

Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.

Build websites from already-built web applications

These out-of-the-box solutions provide you proven, tested applications that can be up and running now.  Build a store, a gallery, or a web-based email solution.

Want your website pre-built and hosted?

Close Windowclose

Rate your experience or provide feedback on this page

Account or customer service questions?
Please user our contact form.

Need technical support?
Please visit support to ask a question

Content

rating

Layout

rating

Ease of use

rating

security code refresh image

We do not respond to comments submitted from this page directly, but we do read and analyze any feedback and will use it to help make your experience better in the future.

Close Windowclose

We were unable to retrieve the attached file

Close Windowclose

Attach and remove files

add attachmentAdd attachment
Close Windowclose

Enter the URL you would like to link to in your post

Close Windowclose

This is how you use right click RTF editing

Enable right click RTF editing option allows you to add html markup into your tutorial such as images, bulleted lists, files and more...

-- click to close --

Uploading file...