How to make window.prompt fields required in javascript - javascript

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
}

Related

Enable submit button only when no error is found

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", "");

How to execute same code for each user with node-telegram-bot-api?

To tell the truth I have no idea how to deal with the following issue.
Using telegram-node-bot-API I wrote a bot. The code is at the link: https://jsfiddle.net/gauo9p0q/
What I need now is:
When user A reaches the point where he is to share his phone I check if the phone is correct or not. If not ans user B start using the bot he gets the message that his phone is incorrect, nevertheless he haven't entered it so far. It happens because object order is the one for all users and the code is executed once for all the users what makes the part
else if (!re.test(msg.text) && order.status && msg.text != "Phone number" && msg.text != "Back" && order.type != "email") {
bot.sendMessage(msg.chat.id, "Phone number is incorrect! Try again")
}
be executed all the time even for user ะก.
How do I work with the whole my code and users A and B separately. In this specific case how do I create object order in a unique way for each user?
First temporarily remove all conditions and just use regex for validate phone number in a function and call that function.
// THis is an example and you should customize that
bot.onText(/^(()?\d{3}())?(-|\s)?\d{3}(-|\s)?\d{4}$/, (msg, match) => {
Extra Info

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.

How To Check For Empty Fields In HTML Form With JavaScript

I'm checking a website registration form with JavaScript code and onchange listeners.
Empty fields/spaces need to be checked for first before checking for illegal characters, too long strings, etc.
I've read this.
But for a null string,
if (field.value ==="")
alert("Empty field!");
this will not generate the desired alert.
People at the end of the above thread suggested that recent browser versions might not accept such a statement.
So, how do I sort out empty/blank/ignored fields ?
EDIT 1
I've already tried
if (!field.value)
but it only provides an alert if the user has already typed some characters in the field and immediately deleted them before entering a blank field. It will not provide an alert just by clicking the mouse on it and then tabbing on to the next field. It looks like I may need to assign a null value to these form fields at the outset . . I am using implicit adding of the changeEvent listener, i.e. on seeing a value explicitly assigned to the onchange attribute of an element, it is activated without any addEventListener(..) statement.
Also,
if (field.value.length == 0)
does not seem to produce any alert.
EDIT 2
Sorted, I think.
I was using the JavaScript null field check as part of a field-by-field validation check on a web form.
I was using onchange as the event handler. This was wrong. What was needed here was onblur since in the case of a completely null field (i.e. a field on which nothing had been entered before tabbing away from it), no change has been effected -- and therefore no onchange event occurs that would trigger a JavaScript alert.
Thanks for your efforts.
I was stuck on this one across a couple of weeks and only sorted it with the help of some experimental programming by a more experienced guy at work here.
In this script you can see an alert of your variable value ( a console.log would be lees noisy :)
The use of === is for type check but in your example does not make sense as you are using an empty string
<script>
var field= {};
checkEquality(field);
field.value = "";
checkEquality(field);
function checkEquality(object){
alert(object.value);
if (object.value === "")
{
alert("===");
}
if(object.value == ""){
alert("==");
}
}
You can use bellow code for check all four(4) condition for validation like not null, not blank, not undefined and not zero only use this code (!(!(variable))) in javascript and jquery.
function myFunction() {
var data; //The Values can be like as null, blank, undefined, zero you can test
if(!(!(data)))
{
alert("data "+data);
}
else
{
alert("data is "+data);
}
}

Javascript || not working

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.

Categories

Resources