Welcome to Code Forum!

Join a community that supports you and your coding journey from day one. We strive to be a friendly, supportive community that empowers everyone to be better developers. By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
  • Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.

    GIF shows where to locate </> in the thread and or post editor toolbar.
    To learn more about how to use our BBCode feature, review our "How to post your code into threads" here.

    Thank you, Code Forum.

JavaScript Help - What is wrong with this code

KeithReilly

New Coder
Hi
I used this code from a YouTube Tutorial and I get an error saying: SyntaxError : missing after case label 5: at line 6

Code is below and any advice would be much appreciated.

Code:
var f = this.getField("City");

switch(event.value){


case "Pakistan"

f.setItems(["Karachi", "Islamabad", "Lahore"]);

break;


case "United States"

f.setItems(["New York", "California", "Nevada"]);

break;


case "United Kingdom"

f.setItems(["Manchester", "Liverpool", "London"]);

break;


case "United Arab Emirates"

f.setItems(["Dubai", "Abu Dhabi", "Sharjah"]);

break;


case "Canada"

f.setItems(["Toronto", "Vancouver", "Montreal"]);

break;
 
Last edited by a moderator:
1. You didn't close switch statement with curly bracket.
2. You didn't add colon after each case.

JavaScript:
var f = this.getField("City");
switch(event.value){

case "Pakistan":
f.setItems(["Karachi", "Islamabad", "Lahore"]);
break;

case "United States":
f.setItems(["New York", "California", "Nevada"]);
break;

case "United Kingdom":
f.setItems(["Manchester", "Liverpool", "London"]);
break;

case "United Arab Emirates":
f.setItems(["Dubai", "Abu Dhabi", "Sharjah"]);
break;

case "Canada":
f.setItems(["Toronto", "Vancouver", "Montreal"]);
break;
}
 
Hi,
I used the same code above, also from the internet, and replaced ("City") with ("Address"). I want to be able to select a company name from a dropdown and have their address auto populate in a text box (I had to use a dropdown instead) below the name. I receive a SyntaxError: syntax error 4: at line 5 Here is what I have:

Code:
var f = this.getField("Address");

switch(event.value){


case: "Alberta Construction Training Institute"

f.setItems(["12118 154 Street NW, Edmonton, AB  T5V 1J2"]);

break;


case: "Canadian Industrial & Construction Training Inc."

f.setItems(["330 MacKenzie Boulevard, Fort McMurray, AB T9H 4C4"]);

break;


case: "First Aid & Safety Services Inc."

f.setItems(["17920 118 Avenue, Edmonton, AB  T5S 2W3"]);

break;


case: "Learn-Rite Courses Inc."

f.setItems(["10129 128 Avenue, Grande Prairie, AB  T8V 1X9"]);

break;


case: "Rhino Integrated Safety Services Ltd."

f.setItems(["#3 6720 71 Street, Red Deer, AB  T4P 3Y7"]);

break;


case: "Safety Buzz Campus"

f.setItems(["350 Eagle Butte Road, Dunmore, AB  T1B 0K2"]);

break;


case: "Safety Connections"

f.setItems(["1007 Factory Street, Medicine Hat, AB  T1A 1X8"]);

break;


case: "--Select--"

f.clearItems();}
 
Last edited by a moderator:
Hi,
I used the same code above, also from the internet, and replaced ("City") with ("Address"). I want to be able to select a company name from a dropdown and have their address auto populate in a text box (I had to use a dropdown instead) below the name. I receive a SyntaxError: syntax error 4: at line 5 Here is what I have:

var f = this.getField("Address");
switch(event.value){

case: "Alberta Construction Training Institute"
f.setItems(["12118 154 Street NW, Edmonton, AB T5V 1J2"]);
break;

case: "Canadian Industrial & Construction Training Inc."
f.setItems(["330 MacKenzie Boulevard, Fort McMurray, AB T9H 4C4"]);
break;

case: "First Aid & Safety Services Inc."
f.setItems(["17920 118 Avenue, Edmonton, AB T5S 2W3"]);
break;

case: "Learn-Rite Courses Inc."
f.setItems(["10129 128 Avenue, Grande Prairie, AB T8V 1X9"]);
break;

case: "Rhino Integrated Safety Services Ltd."
f.setItems(["#3 6720 71 Street, Red Deer, AB T4P 3Y7"]);
break;

case: "Safety Buzz Campus"
f.setItems(["350 Eagle Butte Road, Dunmore, AB T1B 0K2"]);
break;

case: "Safety Connections"
f.setItems(["1007 Factory Street, Medicine Hat, AB T1A 1X8"]);
break;

case: "--Select--"
f.clearItems();}
The colon is supposed to be after the case string, not the case keyword. Put the colon at the end of the line.
 

Buy us a coffee!

Buy me a coffee.
Back
Top Bottom