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.
Related
I have a simple application in which I only want to enable the calculate button only when no-errors are found (an error is recorded if the value is not a number, or a value is less than 0). I perform a few conditional checks using && and || operator. However, when only one input has been filled properly, without errors, the button is enabled. But, when an explicit wrong value has been specified the button is disabled again.
Code: https://github.com/KaustubhMaladkar/Tip-Calculator
if (!peopleError && !billError) {
submit.removeAttribute("disabled");
}
if (billError || peopleError) submit.setAttribute("disabled", "")
Live site: https://kaustubhmaladkar.github.io/Tip-Calculator/
I would like to thank that #Nestoro for their comments on my question as most, if not all, of my answer is based their comments.
This code will solve the problem
if (!peopleError && !billError && Number(billElem.value) && Number(peopleElem.value)) submit.removeAttribute("disabled");
else submit.setAttribute("disabled", "");
I am taking input using window.prompt. There are three prompt one after another. I want to make every prompt box required like we do in form fields. Is there any way to achieve that facility in javascript?
I think you can inspire from below code for every prompt:
let input = prompt('Do something?');
if (input === null || input.trim() === "") {
// execute certain action
}
I am very new to javascript and i am trying to insert multiple conditions in an if statement.
below my js.
if (($("#chkIs_3").is(":checked")) && ($(document.getElementById("two").checked == false) && $(document.getElementById("four").checked == false)))
{
alert("Please check one vehicle type.");
}
If and only if the id's(two, four) are unchecked the alert has to be shown, but for me even if one of the radio buttons is checked the alert is shown.
Please help me in rectifying the probelem.
id = chkIs_3 is a checkbox
id = (two & four) are radio buttons.
You are mixing native Javascript with jQuery, for a start. You're also doing
$(document.getElementById("two").checked == false)
...which is just weird and not valid. The dollar sign $ is just a normal variable name. In this case jQuery is using it as its main function name.
This is what you need instead (in case you're not aware, the exclamation mark ! means "not" and inverts the result of the $("#two").is(":checked")):
if ($("#chkIs_3").is(":checked") && (!$("#two").is(":checked") && !$("#four").is(":checked")))
{
alert("Please check one vehicle type.");
}
I could have sworn I validated everything properly until my teacher decided to look for every single possible combination of characters and somehow doc me for 10 points. So I went in my code and try to fix the validation but, even though this is just like the example in his lecture outline, it decides to let a1 unwantingly pass the form. I double checked the ascii char code chart using this link
and the 1 still keeps getting through. this is my code section:
else if(f1.state.value.length != 2 ||
!( (f1.state.value.charCodeAt(0)>=65 && f1.state.value.charCodeAt(0)<=90) ||
(f1.state.value.charCodeAt(1)>=97 && f1.state.value.charCodeAt(1)<=122) ))
{
alert('Please enter a state in abreviated form');
f1.state.focus();
return false;
}
why does the 1 keep getting through?
edit: also, i notice 1a works (or doesnt work), but not a1..
interesting, i took the ! out and put it around each individual parenthesese to ! and it worked.. so it was returning true if one or the other was true... then !ing it.
so it should have been :
else if(f1.state.value.length != 2 ||
( !(f1.state.value.charCodeAt(0)>=65 && f1.state.value.charCodeAt(0)<=90) ||
!(f1.state.value.charCodeAt(1)>=97 && f1.state.value.charCodeAt(1)<=122) ))
{
alert('Please enter a state in abreviated form');
f1.state.focus();
return false;
}
I'm Working on a banking application in which i have one drop-down box to select Mode of Payment and i have two text fields for Acc No and Bank Name.
I have three inputs for Mode of payment: 1.Bank Transfer,2.Cash and 3.DD/Cheque.Now I would like to display a pop up message If the user selects the Mode of payment as Bank Transfer or DD/Cheque and leaving the two text fields i.e.,Acc No and Bank Name as blank.
MY JavaScript:
if ($F('personnel_bank_detail_mode_of_payment') == 'Bank Transfer' || 'DD/Cheque')
{
if ($F('personnel_bank_detail_account_number') == '')
{
"* Please Enter Bank Account Number\n";
}
if ($F('personnel_bank_detail_bank_id') == '')
{
"* Select Bank Name\n";
}
}
The above code is working if the user selects Bank Transfer but it is not working for DD/Cheque. How Could i make my code to work for both.Any useful suggestions will be appreciated.
Thanks!
You need to repeat what you're comparing.
if ($F('personnel_bank_detail_mode_of_payment') == 'Bank Transfer' || $F('personnel_bank_detail_mode_of_payment') == 'DD/Cheque')
If you're having some trouble with this, you can make this more obvious to yourself in the future by using parentheses around every statement.
if ((something == otherthing) || (something == someotherthing))
For the behaviour you're expecting, both sides of the || need to be something that evaluate to a boolean, which the == operator returns.
The if condition should rather be :
if ($F('personnel_bank_detail_mode_of_payment') == 'Bank Transfer' || $F('personnel_bank_detail_mode_of_payment') == 'DD/Cheque') {
// do your stuff
}
There is definitely something more you need to know about Logical Operators in JavaScript here.