471,338 Members | 900 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,338 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 1927
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by EviL KerneL | last post: by
2 posts views Thread by Wes Weems | last post: by
4 posts views Thread by Scott M. | last post: by
9 posts views Thread by julie.siebel | last post: by
12 posts views Thread by Gustaf | last post: by
1 post views Thread by lilbit02 | last post: by
2 posts views Thread by dkyadav80 | last post: by
reply views Thread by rosydwin | last post: by

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.