Jquery: "Expected Comma but found <character>" error in Netbeans/Eclipse - javascript

Following is code which is giving above error, in netbeans as well as eclipse:
$(".bandListing").autocomplete({
source : [ ${bandnavn} ]
});
The error says:
1) Expected Comma but found {
source:[${bandnavn}]
2) Expected Comma but found ]
source:[${bandnavn}]
${bandnavn} is JSP object containing String of comma separated values which is put into array and assign to source. The code output is fine
Following is screenshot from Netbeans of same; could anyone guide me how to rectify the same?
If it could be fixed without do much changes, that will be helpful.

Store the value returned ${bandnavn} in a JavaScript variable, then use split() to create an array of string which can be supplied to autocomplete
var str = '${bandnavn}';
$(".bandListing").autocomplete({
source : str.split(',')
});

Related

I must replace some special characters on Code by Zapier

I need to replace some special characters on Zapier.
Since there are many substitutions, I want to do it through Code by Zapier.
I made the code, but I got the following error on Code by Zapier:
We had trouble sending your test through.
TypeError: str.replace is not a function
Here is the code:
str = inputData;
str.replace(/Á|Ä|À|Ã|Â/g, "A");
str.replace(/É|Ë|È|Ê/g, "E");
str.replace(/Í|Ï|Ì|Î/g, "I");
str.replace(/Ó|Ö|Ò|Õ|Ô/g, "O");
str.replace(/Ú|Ü|Ù|Û/g, "U");
output = [{outputData: str}];
I don't know why str.replace doesn't work on Code by Zapier. I tried use str = str.replace(), instead str.replace(), but it did not worked too.
Can someone help?
Looks like inputData is not a string but rather an object. So if you provided a field to the Code then you need to access it as a property of that object. Let's say the name of the variable is foo, then you need to access it as inputData.foo.replace() (see screenshot).

How to use `%value%` in javascript?

I am learning JavaScript and I see %value% in a code but I do not know what does it mean or how to use it. Can anyone please help me explain to me. Thank you very much.
var formattedLocation = HTMLworkLocation.replace("%data%", work.jobs[job].location);
"%data%" is just a literal string. This code will take the value of HTMLWorkLocation, look for the first occurrence of %data% in it, and replace that with the value of work.jobs[job].location, and store the resulting string in formattedLocation.
var work = {
jobs: [{
location: "Home office"
}]
};
var job = 0;
var HTMLworkLocation = "John is located at %data%";
var formattedLocation = HTMLworkLocation.replace("%data%", work.jobs[job].location);
console.log(formattedLocation);
This is probably part of a template system that's used to replace placeholders like %data% with values that come from a table.
You're using string.replace which takes a string or regular expression as it's first argument. Based on the code you posted it looks like you're looking for the string "%data%" (or whatever string you're looking for) in HTMLworkLocation and replacing it with the value in work.jobs[job].location. Then it is being stored in formattedLocation.
I would put a debugger; line after that line of code so you can see what the values are in the debugger console. That might help make more sense of things.
Here is more info on the str.replace method with some examples

substr in IE7 not working

I'm trying the following code to extract first few characters from a string stored in a variable.
title.substr(0,35)+"_"+var1+"_"+var2+var3;
At the above line IE7 throws an error:
Object doesn't support this property or method.
Tried: substring and slice as well. Still same issue.
It is quite apparent from the error message that title is not of type string.
Try this:
var title = "abcdefghijklmnopqrstuvwxyz";
console.log(title.substr(0,15));
I suspect your title variable is not of type String. To debug it, try
console.log(typeof(title)) in your own code.
Check the console and see what you get.

Parsing JSON with spaces in key name with AngularJS

I have a json which has spaces in key names.
The JSON has the following format
{
"response":{"docs":[
{
"my name":"krammer",
"job": "stackexchange"
}
}
}
While using ng-repeat to get the parameters into a list, I use the following code
{{friends.['my name']}}
But this gives an empty output. While
friends.my name
gives an error.
So how can the key names with empty spaces be accessed using AngularJS ?
Please try this
{{friends['my name']}}
It doesn't have anything to do with angular, this is the way we read props from JavaScript object, here you have a object called friends. so these are all we can do, if we don't have invalid javascript characters for naming in JavaScript, like space and some other:
friends.myname
friends['myname']
friends["myname"]
but when we have those invalid characters we only can do:
friends['my name']
friends["my name"]
You may run into a case where {{friends['my name']}} does not work. If so, try the following:
{{friends.my_name}}
{{friends['my name']}} will be working fine

javascript object value to string conversion

I am getting the value of input using javascript using below code.
var name=document.getElementById("firstName").value;
Getting output like rk-chaitu.I want to split this output using reg expression.
Now my question is how to convert name object to String?
Regards,
Chaitu
name should already be a string. You can directly use name.split(separator).
EDIT: I see you have added information. Can you post more code? Perhaps the error comes from something else.
The value attribute should already be a String.

Categories