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

Validation on Form Field and Drop Down

Hi, Thanks in advance...

I want to test two form fields:

ConversionValue (text field)
convert (Select Dropdown: Index 0 = True - 1 = False)

Essentially, If ConversionValue is Blank, but convert is True
Then give an error and set convert to false...
Or if ConversionValue is blank and convert is false - skip it.

This is what i have... it all seems to work apart form the first
line with the && is not catching both fileds. IsBlank is a
function for testing the field is not blank and works.
if (IsBlank(document.prodForm.ConversionValue.value) &&
(document.prodForm.convert.selectedIndex.value = 0))
{
document.prodForm.convert.selectedIndex = 1;
alert("You must be enter a Currency Conversion Rate for
Convert to be Enabled!");
document.prodForm.ConversionValue.select();
document.prodForm.ConversionValue.focus();
return false;
}
Many Thanks

----------------------------------------------
Posted with NewsLeecher v2.0 Beta 5
* Binary Usenet Leeching Made Easy
* http://www.newsleecher.com/?usenet
----------------------------------------------

Jul 23 '05 #1
1 2053
InvisibleMan wrote:
Hi, Thanks in advance...

I want to test two form fields:

ConversionValue (text field)
convert (Select Dropdown: Index 0 = True - 1 = False)

Essentially, If ConversionValue is Blank, but convert is True
Then give an error and set convert to false...
Or if ConversionValue is blank and convert is false - skip it.

This is what i have... it all seems to work apart form the first
line with the && is not catching both fileds. IsBlank is a
function for testing the field is not blank and works.
if (IsBlank(document.prodForm.ConversionValue.value) &&
(document.prodForm.convert.selectedIndex.value = 0))
{
document.prodForm.convert.selectedIndex = 1;
alert("You must be enter a Currency Conversion Rate for
Convert to be Enabled!");
document.prodForm.ConversionValue.select();
document.prodForm.ConversionValue.focus();
return false;
}
Many Thanks


(snip)

This is wrong:

document.prodForm.convert.selectedIndex.value = 0

First, you're setting the variable (=) instead of comparing it (==).
Secondly, selectedIndex isn't an object, it's an integer property,
holding the (Select.options[]) array index of the currently selected
option.

if (IsBlank(document.prodForm.ConversionValue.value) &&
(document.prodForm.convert.selectedIndex == 0))

Also, focus first, select second. You can eliminate some of the
repetition as well.

var f = document.prodForm;
if (IsBlank(f.ConversionValue.value)
&& f.convert.selectedIndex == 0)
{
f.convert.selectedIndex = 1;
alert("You must be enter a Currency Conversion Rate for Convert to be
Enabled!");
if (f.ConversionValue.focus)
f.ConversionValue.focus();
if (f.ConversionValue.select)
f.ConversionValue.select();
return false;
}

Sure you want to reset the 'convert' field? Might consider radios for
it as well.

Jul 23 '05 #2

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

Similar topics

5
by: EviL KerneL | last post by:
Hi - I am trying to figure out a way to enforce the validation included for this form based on whether the user chooses "email" or "phone" as the contact choice. Right now it is set to enforce...
7
by: x muzuo | last post by:
Hi guys, I have got a prob of javascript form validation which just doesnt work with my ASP code. Can any one help me out please. Here is the code: {////<<head> <title>IIBO Submit Page</title>...
2
by: Wes Weems | last post by:
I'd like to have a 3 values in a drop down, and have a validator not allow a form submit unless its 2 of the 3 values (eg, one of the values says "select one") I used custom validator and did a...
4
by: Scott M. | last post by:
If I put RequiredFiledValidators on a page and set them up with corresponding TextBoxes everything works just fine. If I add a DropDownList and set its AutoPostBack to True, I am able to post data...
9
by: julie.siebel | last post by:
Hello all! As embarrassing as it is to admit this, I've been designing db driven websites using javascript and vbscript for about 6-7 years now, and I am *horrible* at form validation. To be...
12
by: Gustaf | last post by:
I've been working on a membership form for a while, and find it very tedious to get an acceptable level of form validation. A web search for solutions revealed some home-brewed solutions, such as...
1
by: lilbit02 | last post by:
Hi, I have a form that utilizes validation as most do via javascript. This form worked totaly fine until I needed to add a dynamic div now the validation doesn't work. It does work for the first...
7
by: sharsy | last post by:
Hi guys, I would like to setup a validation rule for a database in microsoft access that restricts data entry so that a certain field can only be filled in if another field has a specific answer...
2
by: dkyadav80 | last post by:
Hi I have prototype.js script.js, validate_form.js and lib,src forlder for valdate the user registration. i want to use other field validation. when user click from drop down "other" then are...
106
by: bonneylake | last post by:
Hey Everyone, Well i don't know if my question should be in javascript/ajax or coldfusion, i figure this is more of a coldfusion question. But if this is in the wrong section let me know an all...
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...
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
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
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
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...
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.