By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,656 Members | 1,027 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,656 IT Pros & Developers. It's quick & easy.

Validation on Form Field and Drop Down

P: n/a
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
Share this Question
Share on Google+
1 Reply


P: n/a
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.