473,406 Members | 2,698 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,406 software developers and data experts.

How to compare values from two dropdowns

I want to compare the min and max values between two dropdowns. This script sometimes gives correct result ...and sometimes not... Pls can u answer me whts goin wrong sometimes.
Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <head>
  3.  
  4. <script type='text/JavaScript'>
  5.  
  6. function validateBox()
  7.  
  8. try
  9. {    var frm = document.form_srch_sales_basic;
  10.      formMinValue = document.form_srch_sales_basic.txtMinPrice.options[document.form_srch_sales_basic.txtMinPrice.selectedIndex].value;
  11.  
  12. formMaxValue = document.form_srch_sales_basic.txtMaxPrice.options[document.form_srch_sales_basic.txtMaxPrice.selectedIndex].value;
  13.  
  14. if(formMinValue > formMaxValue)
  15.             {    
  16.                 alert(formMinValue);
  17.                 alert(formMaxValue);
  18.                 alert("Your Minimum value is Greater then Maximum Value.Please Re-enter Maximum Value!");
  19.                 return false;
  20.             }            
  21.              return true;
  22. }
  23. catch(e)
  24. {
  25. alert(e);
  26. return false;
  27. }
  28. }
  29.  
  30. </script>
  31.  
  32. </head>
  33.  
  34. <body>
  35. <form name="form_srch_sales_basic" onsubmit="return validateBox();" method ="post" action="view_sales.php">
  36.                     <tr>
  37.                      <td align="center" width="95">&nbsp;</td>
  38.                      <td align="left" height="25" >Price Range</td>
  39.                     </tr>
  40.  
  41.                      <select size="1" name="txtMinPrice">
  42. <option value="" selected>No Minimum</option>
  43. <option value="250000">250,000</option>
  44. <option value="500000">500,000</option>
  45. <option value="750000">750,000</option>
  46. <option value="1000000">1,000,000</option>
  47. <option value="1250000">1,250,000</option>
  48. <option value="1500000">from $1,500,000</option>
  49. <option value="2000000">from $2,000,000</option>
  50. <option value="3000000">3,000,000</option>
  51. <option value="5000000">5,000,000</option>
  52. </select>
  53.                  <tr>
  54.                  <td align="center" width="95" height="6"></td>
  55.                  <td align="left" valign="top" height="6"></td>
  56.                 </tr>
  57.                      <select size="1" name="txtMaxPrice">
  58. <option value="" selected>No Maximum</option>
  59. <option value="500000">500,000</option>
  60. <option value="750000">750,000</option>
  61. <option value="1000000">1,000,000</option>
  62. <option value="1250000">1,250,000</option>
  63. <option value="1500000">1,500,000</option>
  64. <option value="2000000">2,000,000</option>
  65. <option value="3000000">3,000,000</option>
  66. <option value="5000000">5,000,000</option>
  67. <option value="8000000">8,000,000</option>
  68. </select>
  69.                      <input type="submit" value="Submit">
  70. </form>
  71. </body>
  72. </html>
  73.  
May 11 '07 #1
3 5991
acoder
16,027 Expert Mod 8TB
Instead of comparing the string value, you need to compare the integer values using parseInt, otherwise "1000000" will be regarded as less than "750000".
Jan 30 '08 #2
kunal pawar
297 100+
Modify ur code, use eval() function at time of comparison.
like below

Expand|Select|Wrap|Line Numbers
  1. <script type='text/JavaScript'>
  2.  
  3. function validateBox()
  4.  
  5. try
  6. {
  7.     var frm = document.form_srch_sales_basic;
  8.      formMinValue = document.form_srch_sales_basic.txtMinPrice.options[document.form_srch_sales_basic.txtMinPrice.selectedIndex].value;
  9.  
  10. formMaxValue = document.form_srch_sales_basic.txtMaxPrice.options[document.form_srch_sales_basic.txtMaxPrice.selectedIndex].value;
  11.  
  12. if(eval(formMinValue) > eval(formMaxValue))
  13.             {    
  14.  
  15.                 alert("Your Minimum value is Greater then Maximum Value.Please Re-enter Maximum Value!");
  16.                 return false;
  17.             }            
  18.              return true;
  19. }
  20. catch(e)
  21. {
  22. alert(e);
  23. return false;
  24. }
  25. }
  26.  
  27. </script>
Jan 30 '08 #3
acoder
16,027 Expert Mod 8TB
Modify ur code, use eval() function at time of comparison.
You should avoid eval wherever possible. parseInt would be fine here.

PS. don't forget those code tags.
Jan 30 '08 #4

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

Similar topics

0
by: Phil Powell | last post by:
/*-------------------------------------------------------------------------------------------------------------------------------- Parameters: $formField1: The name of the first array $formField2:...
16
by: michael | last post by:
Is it possible to get all href URLs contained in a unordered list and place them in an array? Or in fact two different arrays, differently named one for each <ul> group? <ul> <li><a...
0
by: Marc Miller | last post by:
Hi to all, (I apologize that I posted this in dotnet.languages.vb.controls, but I NEED and answer quickly, please) I have an 'employees' datagrid which contains company numbers as labels....
7
by: NCrum | last post by:
I want to set the Default value of a Combobox for any changeable record and have got this working but it is totaly unsatisfactory see the code below I loop through the items in the Combo looking...
11
by: Russ Green | last post by:
How does this: public TimeSpan Timeout { get { return timeout; } set { timeout = value; if(timeout < licenseTimeout) licenseTimeout = timeout; }
0
by: Matthias S. | last post by:
Hi there, first of all, sorry for the lengthy post, but restrictions in my languages skills and the nature of the problem account for it. I've got the following situation: I'm creating a...
7
by: segal.aviad | last post by:
Hi, I'm trying to write a web page containing three dropdowns. The dropdowns are declared as follows: <asp:DropDownList id="cmbCat1" runat="server" AutoPostBack="true"></asp:DropDownList>...
1
by: ganeshshegde | last post by:
Hi, How can i compare values of two dropdown lists in .aspx page using javascript? I used following code- function ValidateFlightRequest() { var vFromCombo =...
0
by: sbart | last post by:
I am programing in asp.net vb using AjaxToolkit cascadingDropDown. I do not have access to AjaxToolkit cascading dropdown event handlers. I have a series of dropdowns. The selection from one of...
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: 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...
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
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...
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...
0
agi2029
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,...

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.