简体   繁体   中英

Javascript validation of Adobe form (radio buttons)

I'm having difficulty (I'm new to JavaScript) figuring out a little validation in Adobe LiveCycle forms. I have a first choice (4 option) radio button, 2nd choice (same 4 options) and 3rd choice (same 4 options) where I'd like a validation to make sure the user doesn't enter the same result 3 times.

I thought it would be something like:

event.rc = true;
if (  form1.#subform[0].FirstChoice.rawValue !=   form1.#subform[0].SecondChoice.rawValue ! &&  form1.#subform[0].FirstChoice.rawValue !=  form1.#subform[0].ThirdChoice.rawValue !)
{
    app.alert("You need three separate answers, you dimwit!");
    event.rc = false;
}

Evidently, I am being a dimwit and going about this all wrong, but I've drawn a blank.

I was thinking also along the lines of:

form1.#subform[0].FirstChoice.rawValue <>   form1.#subform[0].SecondChoice.rawValue ! &&  form1.#subform[0].FirstChoice.rawValue !<>  form1.#subform[0].ThirdChoice.rawValue !)

but I don't know where to go with it.

Help (please), thanks.

You are pretty close. Try:

if ((Select1.rawValue != null && Select1.rawValue == Select2.rawValue) || (Select2.rawValue != null && Select2.rawValue == Select3.rawValue) || (Select3.rawValue != null && Select1.rawValue == Select3.rawValue))
{
    app.alert("You need three separate answers, you dimwit!");
}

You need to cover the case where the Selections are not yet filled in. Select1, Select2, and Select3 are the RadioButton group.

I would put this as a calculation on a hidden field since you want it to recalculate whenever a change is made to the radio buttons.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM