Match field values

I am configuring code to match criteria, if user input value, matches the value of the text 901.
If user input matches the text901 value, submit button will show correct, if user input value, does not match with text901, submit button will show incorrect. Any can help in this. Thanks.

Hi @suffianansari ,
Can you add some more information about what you are trying to do? Will the user see text901 and does its value change? Are you trying to hide and show the “correct” and “incorrect” buttons?
Thanks,
Tova

If i understand the question correctly i think he just wants the check if the the user input is equal to the text901.
depending on that he wants to show correct or incorrect message.

Hi Tova and Kristof,
Thanks for commenting,
I am trying to create quizzes with dynamic pages, my explanation is that, if a user inputs the text in user input text box,
like 1+1=2 or 1+2=3

If the user input answer is correct, correct answer can be displayed, if it is incorrect, incorrect answer can be displayed,

I have different questions, like 1+2=3, 4+2=6.

How I can configure the code in dynamic pages, I do not know whether I need text901 or not. I hope I explained my case. Thanks.

@suffianansari
i would do it as following.

 let answer1 = 3
 let answer2 = 5
 let answer3 = 25

 // when submitting on question 1
 if ($w("#questionInput1").value === answer1.toString()) {
 //show correct
    } else {
 //show incorrect
    }

There is probably a much better way to do this.
just typed some basic code to answer your question.

the “let answer1 = 3” is the same as your text901 only you do not have to add multiple text fields to your page.
the ".toString() " is to validate between a string and a number.
you also can just define it like this : answer1 = “1”
this way you do not have to use the .toString()

also if you want to make sure nothing goes wrong you can make a formule to check if the answer is correct or not.


let firstnumber = 2;
 let secondNumber = parseInt($w("#userInput").value) // gets ur userInput text to a number
 let answer = 7

 if ((firstnumber + secondNumber) === answer) {
 //show correct
    } else {
 //show incorrect
    }

this way you might be able to work with a random number generator
and work with a diffeculty.
depends on what you want to do with it afcourse :grin:
Hope this helps.

Thanks for the explanation, @suffianansari .

There are different ways to implement what you are trying to do. One idea is the following:

  1. Store the first number, the sum, and the missing number (the answer) for each question in separate fields in a database collection.

  2. Connect the first number and the sum to text elements on your dynamic page using a dynamic dataset.

  3. Hide the correct/incorrect/correct answer elements on load using the properties panel.

Then you can write code to:

  1. Check the value of the input against the value of the answer in your collection using getCurrentItem() .

  2. If it’s correct, show the “correct” message.

  3. If it’s incorrect, show the “incorrect” message and the “correct answer” message with the value of the answer stored in your collection.

HTH,
Tova

Hi, @talyaro Thanks for the help,

I am just confused where do I have to code the getCurrentItem().

I tried the code with submit button, I am not doing correctly,
I have connected first number, the sum, and the missing number (the answer) in the database, but cannot figure out, how to use getCurrenItem().

I have used below code. Appreciate your help on this.

export function b1_click(event) {
$w( “#correct” ).show();
$w( “#incorrect” ).show();
$w.onReady( () => {
$w( “#dynamicDataset” ).onReady( () => {
let input1 = $w( “#dynamicDataset” ).getCurrentItem();

} );

} );
}

Hi, @volkaertskristof thanks for the help. The first option is easy to use. Just wanted to know how I can use that code in dynamic pages, where questions and options will be different. I used below code in static page,

export function button80_click(event) {
let answer1 = 1
let answer2 = 5
let answer3 = 25

// when submitting on question 1
if ($w( “#input3” ).value === answer1.toString()){
$w( “#box10” ).show();
} else {
$w( “#box9” ).show();
}
}

Hi @suffianansari ,
getCurrentItem() essentially allows you to access the item in your database collection corresponding to the currently displayed dynamic item page.

Let’s say you stored the answer to each question in a field in your collection called “answer”. You could write something like this:

export function b1_click(event) {  
 $w("#dynamicDataset").onReady( () => {
  let item = $w("#dynamicDataset").getCurrentItem(); 
  let userAnswer = $w("#input3").value; 
  if (userAnswer === item.answer) {
   $w("#correct").show();
  } else {
   $w("#incorrect").show();
  }
 });
}

Hi, @talyaro many thanks. It is working. Really like your support.

Now that Tova axplained it with datasets, you can start making fulk questions with it.
If you have your dataset with different rows (number,question, number1, questionAnswer, equalsto)
Number = 1(sort of a unique number to know this is the first question)
Question = the text for your question (Q1 : what number is missing)
Number1 = a number (5)
QuestionAnswer = the input they have to be equal to (7)
Equalto = your end number1 + questionAnswer = 12
This way you can define all in the dataset and you only have to know on wich question the user is.

Kristof.

Great, @suffianansari . Glad to help. :slight_smile: