Is this IF statement set up correctly?

I am automating an email from the form on my website and it has worked perfectly thus far. However, I want to make a tweak to the code to only send an email to a member of our team if certain criteria is met. So basically I want to create an if statement that basically says "if drop down 6 = “St. George” , run function “sendEmailToBrandon”. I already have everything defined and set up in the backend, I just don’t know if this IF statement it set up correctly.

if ($w(“#dropdown6”.value) === “St. George”) {
sendEmailToBrandon(subject, body)
.then(response => console.log(response));
}

Thoughts??

Thanks!

@brett-haralson think you might be able to shed a little light here? :slight_smile:

I’ll watch this thread - I’m sure someone will respond to you. :slight_smile:

just run it like this, once you see the console.log confirmation you know it is set up correctly. Then just add the additional code to send your email…

$w.onReady( function () {

if ($w(‘#dropdown6’).value === “St. George”) {

console.log("if statement is set up correctly"); 

//enter some more code here to execute

}
})

Ok, I tried that but it says “the value passed to the element selector function (usually $w), must be of type string” any thoughts on proceeding?

@caden-wilding
what way have you your dropdown set up ?

@mikemoynihan99 it’s just set up with two labels, each with values that match the label, so Lehi, Lehi & St. George, George. Then it’s attached to our databse. Does that answer your question?

@caden-wilding
have you physically typed in the values and labels on the dropdown ?

@mikemoynihan99 yep!

@caden-wilding

try add an onClick event…

$w.onReady( function () {

//place a button on your page and call it button1

$w(‘#button1’).onClick(function () {

if ($w(’ #dropdown6 ').value === “St. George”) {
console.log(“if statement is set up correctly”);

//enter some more code here to execute
}
})
})

@mikemoynihan99 already tried that and it shows up with the same error in the dev console

@caden-wilding
ok just place a new dropdown on your page and don’t change anything on it, just give it an id called dropdown1 and execute the below code. does it work ?

$w.onReady( function () {

if ($w(‘#dropdown1’).value !== “Vanilla”) {

console.log("if statement is set up correctly"); 

//enter some more code here to execute

}
})

@mikemoynihan99 got it to show in the console by using the following: sorry for the low quality image, wix code forum is struggling on my computer and I have to respond on my phone

PS

@caden-wilding
thats the same as this code posted 2hrs ago

if ($w(’ #dropdown6 ').value === “St. George”) {
console.log(“if statement is set up correctly”);
//enter some more code here to execute }

@mikemoynihan99 yeah I’m not sure why it didn’t work before with the on Ready function or the button click function. Regardless, the email is still not sending when nested in an if function. I can get the email to send without the if statement, but as soon as I add the if function it won’t send :face_with_raised_eyebrow: