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. -
<html>
-
<head>
-
-
<script type='text/JavaScript'>
-
-
function validateBox()
-
{
-
-
try
-
{ var frm = document.form_srch_sales_basic;
-
formMinValue = document.form_srch_sales_basic.txtMinPrice.options[document.form_srch_sales_basic.txtMinPrice.selectedIndex].value;
-
-
formMaxValue = document.form_srch_sales_basic.txtMaxPrice.options[document.form_srch_sales_basic.txtMaxPrice.selectedIndex].value;
-
-
if(formMinValue > formMaxValue)
-
{
-
alert(formMinValue);
-
alert(formMaxValue);
-
alert("Your Minimum value is Greater then Maximum Value.Please Re-enter Maximum Value!");
-
return false;
-
}
-
return true;
-
}
-
catch(e)
-
{
-
alert(e);
-
return false;
-
}
-
}
-
-
</script>
-
-
</head>
-
-
<body>
-
<form name="form_srch_sales_basic" onsubmit="return validateBox();" method ="post" action="view_sales.php">
-
<tr>
-
<td align="center" width="95"> </td>
-
<td align="left" height="25" >Price Range</td>
-
</tr>
-
-
<select size="1" name="txtMinPrice">
-
<option value="" selected>No Minimum</option>
-
<option value="250000">250,000</option>
-
<option value="500000">500,000</option>
-
<option value="750000">750,000</option>
-
<option value="1000000">1,000,000</option>
-
<option value="1250000">1,250,000</option>
-
<option value="1500000">from $1,500,000</option>
-
<option value="2000000">from $2,000,000</option>
-
<option value="3000000">3,000,000</option>
-
<option value="5000000">5,000,000</option>
-
</select>
-
<tr>
-
<td align="center" width="95" height="6"></td>
-
<td align="left" valign="top" height="6"></td>
-
</tr>
-
<select size="1" name="txtMaxPrice">
-
<option value="" selected>No Maximum</option>
-
<option value="500000">500,000</option>
-
<option value="750000">750,000</option>
-
<option value="1000000">1,000,000</option>
-
<option value="1250000">1,250,000</option>
-
<option value="1500000">1,500,000</option>
-
<option value="2000000">2,000,000</option>
-
<option value="3000000">3,000,000</option>
-
<option value="5000000">5,000,000</option>
-
<option value="8000000">8,000,000</option>
-
</select>
-
<input type="submit" value="Submit">
-
</form>
-
</body>
-
</html>
-
3 5991
Instead of comparing the string value, you need to compare the integer values using parseInt, otherwise "1000000" will be regarded as less than "750000".
Modify ur code, use eval() function at time of comparison.
like below - <script type='text/JavaScript'>
-
-
function validateBox()
-
{
-
-
try
-
{
-
var frm = document.form_srch_sales_basic;
-
formMinValue = document.form_srch_sales_basic.txtMinPrice.options[document.form_srch_sales_basic.txtMinPrice.selectedIndex].value;
-
-
formMaxValue = document.form_srch_sales_basic.txtMaxPrice.options[document.form_srch_sales_basic.txtMaxPrice.selectedIndex].value;
-
-
if(eval(formMinValue) > eval(formMaxValue))
-
{
-
-
alert("Your Minimum value is Greater then Maximum Value.Please Re-enter Maximum Value!");
-
return false;
-
}
-
return true;
-
}
-
catch(e)
-
{
-
alert(e);
-
return false;
-
}
-
}
-
-
</script>
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.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Phil Powell |
last post by:
/*--------------------------------------------------------------------------------------------------------------------------------
Parameters:
$formField1: The name of the first array
$formField2:...
|
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...
|
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....
|
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...
|
by: Russ Green |
last post by:
How does this:
public TimeSpan Timeout
{
get { return timeout; }
set
{
timeout = value;
if(timeout < licenseTimeout)
licenseTimeout = timeout;
}
|
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...
|
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>...
|
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 =...
|
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...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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
|
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...
|
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...
|
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: 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,...
|
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...
|
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: 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,...
| |