473,385 Members | 1,707 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,385 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 2052
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.