Validation on Form Field and Drop Down

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • InvisibleMan

    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(docume nt.prodForm.Con versionValue.va lue) &&
    (document.prodF orm.convert.sel ectedIndex.valu e = 0))
    {
    document.prodFo rm.convert.sele ctedIndex = 1;
    alert("You must be enter a Currency Conversion Rate for
    Convert to be Enabled!");
    document.prodFo rm.ConversionVa lue.select();
    document.prodFo rm.ConversionVa lue.focus();
    return false;
    }


    Many Thanks

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

  • RobB

    #2
    Re: Validation on Form Field and Drop Down

    InvisibleMan wrote:[color=blue]
    > 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(docume nt.prodForm.Con versionValue.va lue) &&
    > (document.prodF orm.convert.sel ectedIndex.valu e = 0))
    > {
    > document.prodFo rm.convert.sele ctedIndex = 1;
    > alert("You must be enter a Currency Conversion Rate for
    > Convert to be Enabled!");
    > document.prodFo rm.ConversionVa lue.select();
    > document.prodFo rm.ConversionVa lue.focus();
    > return false;
    > }
    >
    >
    > Many Thanks[/color]

    (snip)

    This is wrong:

    document.prodFo rm.convert.sele ctedIndex.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(docume nt.prodForm.Con versionValue.va lue) &&
    (document.prodF orm.convert.sel ectedIndex == 0))

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

    var f = document.prodFo rm;
    if (IsBlank(f.Conv ersionValue.val ue)
    && f.convert.selec tedIndex == 0)
    {
    f.convert.selec tedIndex = 1;
    alert("You must be enter a Currency Conversion Rate for Convert to be
    Enabled!");
    if (f.ConversionVa lue.focus)
    f.ConversionVal ue.focus();
    if (f.ConversionVa lue.select)
    f.ConversionVal ue.select();
    return false;
    }

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

    Comment

    Working...