Use of variables in a repeater database based

Hey!
I’m trying to make an “Exam Correction” page and i got stucked…
My studens already uploaded their answers (For each question they uploaded a photo of their resolution) and everything is in a Database…
So my problem is that, when I try “to pull” these images in an Image Element i got an error…
The page architecture is pretty simple:

  • A Dropdown to choose the question to correct (Each teacher will correct the same question of all students)
  • A repeater with:
    - An image element (To show the student’s answer)
    - A Dropdown with the number 1, 2, 3 and 4 to give a grade to the student
    - A Text box to leave some words about their “perfomance”

But when a try to pull the images to the element i got an error, the idea for the code is: When the teacher selects the question he’ll correct, the reapeater will show all students who did that question:

export function button18_click(event) {
// Add your code for this event here:
var qN = $w( ‘#dropdown1’ ).value

$w( “#repeater1” ).onItemReady( ($item, itemData, index) => {
$item( “#imageX1” ).src = itemData.url+qN;
} );
wixData.query( “answersheet29220” )
.find()
.then( (results) => {
$w( “#repeater1” ).data = results.items;
} );

The “itemData.url” is the “column” in the database which has the answer (Answer 1 in “url1!”, answer 2 in “url2”, etc)
When I put any fixed valor (Like itemData.url1), the code runs correctly, but when place the variable “qN” i got these error message:

Wix code SDK error: The “src” property cannot be set to “undefined2”. It must be a valid URL starting with “http://”, “https://”, or “wix:image://”.

The number in “undefined” varies with the value of “#drobdown1
I tried a lot of changes to make that code works, but don’t know how…
Anyone knows WHY that error occours? If I could know why, maybe i can fix this error :sweat_smile:

What is #button18? The Repeater’s onItemReady() function does not belong in a click event handler, it should be in the page’s onReady() function.

What is the value of qN? For whatever reason, it is either undefined, or it breaks the URL which is why you’re getting that error. Perhaps add a console.log() statement after you get the value from the dropdown to make sure you have a valid value:

console.log('qN', qN);

Are you sure that you have valid values in the dropdown?