473,657 Members | 2,550 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Retaining Selected Value OnChange

2 New Member
Greetings

I have a drop down list populated by my sql server database. The data on this ASP page consists of numbers that I use to calculate a grand total. This is performed by a javascript function. See below...
function CalculateGrandT otal(SubTotal, ServiceFee)
{
var shippingSelect = document.getEle mentById('shipp ing');
var shippingRequest ed = shippingSelect. options[shippingSelect. selectedIndex].value;
var grandTotal = Number(shipping Requested) + Number(ServiceF ee) + Number(SubTotal );
return grandTotal.toFi xed(2)
}

This function is called once on the page in the following format...
<script type="text/javascript">
document.write( '$' + CalculateGrandT otal(999,999))
</script>

This function works fine for me, until I change the drop down value. At that point, I need an onchange event to refresh the page which will then recalculate a different grand total because the selected value for the drop down will be different. The only problem is when I refresh the page, the drop down value defaults back to the top value.

What should I do that will allow me to mantain the selected value in the drop down which will allow my function to calculate an accurate grand total.

Thanks in advance
Jan 4 '07 #1
2 7278
b1randon
171 Recognized Expert New Member
Greetings

I have a drop down list populated by my sql server database. The data on this ASP page consists of numbers that I use to calculate a grand total. This is performed by a javascript function. See below...
function CalculateGrandT otal(SubTotal, ServiceFee)
{
var shippingSelect = document.getEle mentById('shipp ing');
var shippingRequest ed = shippingSelect. options[shippingSelect. selectedIndex].value;
var grandTotal = Number(shipping Requested) + Number(ServiceF ee) + Number(SubTotal );
return grandTotal.toFi xed(2)
}

This function is called once on the page in the following format...
<script type="text/javascript">
document.write( '$' + CalculateGrandT otal(999,999))
</script>

This function works fine for me, until I change the drop down value. At that point, I need an onchange event to refresh the page which will then recalculate a different grand total because the selected value for the drop down will be different. The only problem is when I refresh the page, the drop down value defaults back to the top value.

What should I do that will allow me to mantain the selected value in the drop down which will allow my function to calculate an accurate grand total.

Thanks in advance
[HTML]
<select onchange="Calcu lateGrandTotal( this.value,999) ;"></select>
Grand total: $<div id="total"></div>
[/HTML]
&
Expand|Select|Wrap|Line Numbers
  1. function CalculateGrandTotal(SubTotal, ServiceFee)
  2. {
  3.     var shippingSelect = document.getElementById('shipping');
  4.     var shippingRequested = shippingSelect.options[shippingSelect.selectedIndex].value;
  5.     var grandTotal = Number(shippingRequested) + Number(ServiceFee) + Number(SubTotal);
  6.     document.getElementById('total').innerHTML = grandTotal.toFixed(2);
  7. }
  8.  
Something like that.
Jan 4 '07 #2
rk330
2 New Member
Thanks! I will try that. But I noticed your code no longer calls the function unless the drop down is changed. When the user first loads this page, a total calculation is required because I will have a default value in the drop down.

If I call the function within the body tag using onload, will that create a conflict when the onchange method calls it as well? Because at this point the function would be called twice and at the same time (onchange and onload)

Thanks again
Jan 4 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

1
6620
by: cgplays.com | last post by:
I have a select-pulldown at http://computergroupplays.com/fb-pres2.asp that changes the 3rd pulldown (Dbase) depending on what the user enters in the 2nd (Wk). My associate wants the values inside the select box to retain their values after hitting the Go-Submit button when selecting the 3 choices- they want to see the values retained on the next page when you look at the form. Below is the include file used to generate the dynamic...
4
6296
by: Dan | last post by:
Can anyone offer suggestions on how to do this or if it is possible? I have a form that uses a drop down box and 2 text fields. What I am trying to do is have the value of each text box set by the choice from the drop down box. Something like: <form name="populatefrm" id="contactfrm" method="post"
1
2758
by: smash2004 | last post by:
I want to keep selected values in select list when i click on another option...with a click on a mouse... if i have 3 options in select list and i click first option..it gets selected..if i then click on third option ..it gets selected but i want also the first option to stay selected when i click on option that is already selected, then it should be deselected
8
2292
by: rkrishna | last post by:
I have an issue that I am trying to solve. I have three select lists (supposed to be preference 1, 2,3) and each of them have the same three options. As soon as I select one of the choices from list1, i would like to remove it from the options of list 2 and so on for list 3. So effectively, List 2 has two choices and List3 only has one choice that can be made. Any pointers on how to accomplish this?
2
8080
by: Monty | last post by:
I use a SELECT dropdown as the nav interface for jumping to a chosen page number. When I setup up the SELECT element on the page, I want to show the user the current page number they are on, so, I put "selected" next to the page number, as shown below: ------------------------------- <form name="pick" method="post" action="showit.php"> <select name="pggo" onChange="this.options.selected;document.pick.submit();">
2
6312
by: php_Boi | last post by:
i have designed an application that is a dynamic submission form. i have text fields and listboxes. now i am able to retain the values of the listboxes when i populate the listbox "manually"(single listbox) like this... <select name="title"> <option value="1"<?php if ($_POST == '1') { echo 'selected="selected"'; } ?>></option> <option value="Mr"<?php if ($_POST == 'Mr') { echo 'selected="selected"'; } ?>>Mr</option>
7
88017
by: pardesiya | last post by:
Friends, I need to write a javascript function (which will be called on clicking a button) to return the currently selected item from a drop- down list whose rendered html is below. <select name="ddlQuery" onchange="javascript:setTimeout('__doPostBack(\'ddlQuery\',\'\')', 0)" id="ddlQuery" style="width:273px;"> <option value="Munich">Munich</option>
9
9912
by: ajos | last post by:
Hello friends, After thinking about this for sometime, i decided to post this in the java forum. Well my problem here in detail is, i have 3 jsp pages where in a.jsp(for example) i have a combo box, based on the selection of the value in that combo box, b.jsp page gets populated with the value associated to a.jsp, and again based on the selection of value of the 2nd combobox my 3rd combo box gets populated, which is in c.jsp. I'm able to...
15
23271
by: ajos | last post by:
Hello all, Im making a dependent drop down for my application for filtering purpose. I have populated the drop down from the database and retrieved in the html. <tr> <td valign="top" width="138" height="26"><small><font face="Verdana"><strong>Branch</strong></font></small></td> <td width="379" height="26"> <select name="branch" size="1" onChange="messValue()"> <option value="">(select branch)</option> <% ...
0
8425
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8326
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8845
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, 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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8743
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8522
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
8622
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 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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
4333
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2745
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
2
1973
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.