Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
i am using a javascript to get data and put it into a table, i dont know where i have gone wrong? please help!
my code is:
function getSOCsForJobTitle() {
var searchtitle = s("#search-input").val();
var apiurl = "http://api.lmiforall.org.uk/api/v1/soc/search?q="
var apicall = apiurl + searchtitle;
s.get(apicall.function (data) s.each(data.function (i.e) {
var tablerow = s("<tr></tr>");
tablerow.append("<td>" + e.title + "/td>");
tablerow.append("<td>" + e.SOC + "/td>");
s("#SOCstable").append(tablerow);
});
});
}
s(function () {
// this gets called when the page loads
s("#search-go") onclick(getSOCsForJobTitle);
});
apicall.function (data) s.each(data.function (i.e) {
First:
apicall is a string, so it won't have a function property. Presumably you are trying to pass it and the function as separate arguments to s.get. You need a comma, not a period.
apicall, function (data) s.each(data.function (i.e) {
Second:
It looks like you are trying to pass an anonymous function as the second argument. The syntax for that is:
function (arg) {
// expressions
}
You are missing the {.
apicall, function (data) {
s.each(data.function (i.e) {
Third:
It looks like you've made exactly the same error for what you are trying to pass to s.each.
s --> $
s("#search-go") onclick --> $("#search-go").click
Related
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 1 year ago.
Improve this question
I am working on a Blazor server project and have this button in my component
<button type="button" class="btn btn-primary" #onclick="#GetUserInput">Add Name</button>
Here is the code I have that the click event is calling
protected async void GetUserInput()
{
var result = await JsRuntime.InvokeAsync<string>("getName");
}
function getName() {
var retVal = prompt("Enter Name : ", "name here");
return retval;
}
In the javascript function, retVal has a value but in the GetUserInput method,
the code crashes with the error message below
ReferenceError: retval is not defined
at getActivityName (https://localhost:44318/script.js:15:11)
at https://localhost:44318/_framework/blazor.server.js:1:70045
at new Promise (<anonymous>)
at e.beginInvokeJSFromDotNet (https://localhost:44318/_framework/blazor.server.js:1:70011)
at https://localhost:44318/_framework/blazor.server.js:1:26293
at Array.forEach (<anonymous>)
at e.invokeClientMethod (https://localhost:44318/_framework/blazor.server.js:1:26263)
at e.processIncomingData (https://localhost:44318/_framework/blazor.server.js:1:24201)
at e.connection.onreceive (https://localhost:44318/_framework/blazor.server.js:1:17286)
at WebSocket.i.onmessage (https://localhost:44318/_framework/blazor.server.js:1:46503)'
I am not sure what is going on? Any ideas?
Javascript is case sensitive. retVal, not retval - JS won't complain about "retval" - it's just undefined.
function getName() {
var retVal = prompt("Enter Name : ", "name here");
return retVal;
}
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 3 years ago.
Improve this question
let people = ['John','Sally','Jake','Chris'];
const logPerson = (person, index) => {
console.log('${index} - Hello ${person}');
};
people.forEach(logPerson);
it keeps printing out like this
"${index} - Hello ${person}"
how do I get it to display the names & index value code looks right as far as I can tell and from what I searched on google.
let people = ['John','Sally','Jake','Chris'];
const logPerson = (person, index) => {
console.log(`${index} - Hello ${person}`);
};
people.forEach(logPerson);
You need to use the BACKTICK, not the regular quote.
console.log(`${index} - Hello ${person}`);
If you are on the US keyboard, that symbol is just above the tab key, right beside the 1 key.
const logPerson = (person, index) => {
console.log(`${index} - Hello ${person}`);
};
people.forEach(logPerson);
In order to reference variables like this you need to use a backquote. However, if you are going to use regular quotes, you can use commas within your string if that is easier:
const logPerson = (person, index) => {
console.log(index, "- Hello", person);
};
The code above will give you the same output. You can also use the plus operator. Whichever form you choose is up to you, but use the backquote when you are trying to reference variables the way you need. Use normal quotes when attempting to reference variables normally and concatenating them within a string using the + or , operators.
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 3 years ago.
Improve this question
I'm passing some value on a onclick=function('') function but the value is not getting passed
while ($row = mysqli_fetch_array($result)) {
$id = $row['id'];
echo '<img class="rmv-img" src="img/bin-with-lid.png">';
}
function DeleteUser(deleteid){
var conf = confirm("deleteid");
if (conf == true) {
$.ajax({
url: "submit/graduation-submit.php",
type :'POST',
data: { deleteid : deleteid},
});
}
}
Here in the parameter I should get the value of id but on the alert side, this is showing deleteid itself
The problem is only the double quotes:
var conf = confirm(deleteid);
This will show the value of the id in the alert.
You are not passing argument to your confirm box,
var conf = confirm("deleteid");
Passing "deleteid" is nothing but a string and not an argument. If you want to show deleteid on confirm box then do this,
var conf = confirm("Are you sure, you want to delete "+deleteid);
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 4 years ago.
Improve this question
https://jsfiddle.net/a/2L4t9saq/217/ is my fiddle
most of the code you can ignore, here is the function:
var modGrid = function(code){
var arr = code
console.log(arr)
for(var n=1;n<gridx+1;n++){
for(var i = 1; i<gridy+1; i++){
var garbledMess = "[x="+i+"][y="+n+"]"
var idea = arr[0]
arr.shift()
$(garbledMess).css("background-color",idea)
}
}
}
the syntax error is as follows:
Uncaught TypeError: arr.shift is not a function
at modGrid ((index):44)
at window.onload ((index):81)
since the modGrid function takes in an array (in the case of my code an array of 4 elements) the .shift() function should be removing the first option in the array, it worked before i added some more code, but now it is apparently not a function
many thanks
since the modGrid function takes in an array
It is designed to take an array, but that isn't what you are passing it.
You are passing it a string, another string, a number and another number.
modGrid('rgba(255,0,0,1)','rgba(0,255,0,1)',2,1);
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
I'm doing my first project using AngularJS and now i've run into a JavaScript problem that just can't understand. Perhaps this is trivial to someone more experienced in JS, if so i hope you guys can help me :)
I've doing this string comparison in function, that receives an id passed as a parameter from a view, which it then compares to id of objects kept in the service:
for (var i = 0; i < this.Sessions.length; i++) {
if (this.Sessions[i].sessionId === sessionId) {
for (var j = 0; j < this.Sessions[i].Instances.length; j++) {
if (this.Sessions[i].Instances[j].instanceId === instanceId);
{
console.log("InstanceId's: " + this.workoutSessions[i].Instances[j].instanceId + " " + instanceId);
//Do stuff and return.
}
}
}
}
When i run the method all the instanceId's of all the instances will evaluate to true.. Why??? As far as i know i'm just comparing strings, but i guess not. The outer comparison works as it should, which makes it even stranger to me.
Output in console, showing that they evaluate to true no matter the value of the strings.
InstanceId's: l0h34qzzgdlpu8fr 42p9smh9kxdsfw29
InstanceId's: 42p9smh9kxdsfw29 42p9smh9kxdsfw29
Really what i want to do is stop the function as soon as i've found the correct instance, but if i put in a return statement inside the IF-block my compiler tells me the j++ statement is unreachable, indicating no matter what the expression is going to be true, and... that is just beyond me.
How the parameter is passed from the view:
<div ng-repeat="instance in session.Instances">
//Some form controls here...
<div style="float: right;">
<button class="btn btn-default" ng-click="addOne(session.sessionId, instance.instanceId)"> + 1</button>
<button class="btn btn-default">Remove</button>
</div>
</div>
Can anybody help??
Thanks in advance.
if (this.Sessions[i].Instances[j].instanceId === instanceId);
the colon at the end seems to be the culprit...
delete the semicolon in the if clause.
Your Code will be same as
if (this.Sessions[i].Instances[j].instanceId === instanceId)
{
;
}
{
console.log("InstanceId's: " + this.workoutSessions[i].Instances[j].instanceId + " " + instanceId);
//Do stuff and return.
}