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);
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 does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
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.
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.
Improve this question
I'm trying to lookup a field's value, if it equals '1', then put the value '1' in different field, if not put a '0'.
I'm not sure why this isn't working, can anyone help?
<input type="text" name="_1_1_33_1_id" value="" onchange="checkLineManager();">
<input class="valueeditable" type="text" name="_1_1_118_1" id="_1_1_118_1" value="" >
Javascript:
function checkLineManager() {
if (document.getElementsByName('_1_1_33_1_id').value == '1') {
document.getElementById('_1_1_118_1').value = '1';
} else {
document.getElementById('_1_1_118_1').value = '0';
}
}
http://jsfiddle.net/nbren007/o9xp0efy/
Note the plural use of "elements" in the following line:
if (document.getElementsByName('_1_1_33_1_id').value == '1') {
This doesn't return an element, it returns a node list.
// To confirm that
alert(document.getElementsByName('_1_1_33_1_id').toString());
So you need to use:
if (document.getElementsByName('_1_1_33_1_id')[0].value == '1') {
There are other ways of accessing the element as well. Most notably through the form element approach.
The hint is in the method: getElementsByName returns more than one element - it returns an array of matching elements.
You need to use array notation to select the element from the array.
Change:
document.getElementsByName('_1_1_33_1_id')
To:
document.getElementsByName('_1_1_33_1_id')[0]
if (document.getElementsByName('_1_1_33_1_id')[0].value == '1') {
document.getElementById('_1_1_118_1').value = '1';
} else {
document.getElementById('_1_1_118_1').value = '0';
}
Or even neater, use a ternary statement:
document.getElementById('_1_1_118_1').value =
document.getElementsByName('_1_1_33_1_id')[0].value == 1 ? '1' : '0';
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
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I have a loop with the jquery .each function that is filtering through IDs with the suffix _prop_val I then get the prefix and use it for other operations as you can see in the code below. At the moment I am having to use an if statement to set the rlPrice. Is there a way to get it in the loop i.e. prefixPrice and then have it set as rlPrice afterwards
$('[id$="_prop_val"]').each(function(){
var prefix = this.id.slice(0,2);
if( $('#'+prefix+'_prop_val').val() != ""){
$('#'+prefix+'_prop_val').prop('disabled', false).trigger('chosen:updated');
$('#'+prefix+'_ct_row').show();
$('#'+prefix+'_deactivate_btn').show();
if(prefix == "rl"){
rlPrice = $('#rl option:selected').data("unit-price");
}
checkExtra(prefix);
}else{
$('#'+prefix+'_container').addClass('inactive');
$('#'+prefix+'_activate_btn').show();
}
});
You might find an object more useful here. Define it before the loop:
var price = {};
Then in your loop just assign the price to a property with the prefix as a key - no need to check for a condition:
price[prefix] = $('#rl option:selected').data("unit-price");
Then you can just access the price using the prefix:
var rlPrice = price['rl'];
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I will do a function with parameters that get a regex and check the field of a form with it.
I have this code:
//The first function handler (no one runs):
field.onblur = function(){
checkField(0, /^([a-z ñáéíóúü]{2,60})$/i, "name", "nameError", "Error in name");
}
//The function:
function checkField(numForm, regex, idField, idError, error){
var form = document.getElementsByTagName("form")[numForm];
var field = form.getElementById(idField);
var spanError = form.getElementById(idError);
//Since here runs, so I think the problem is with the regex
if(!regex.test(idField.value))
spanError.innerHTML = error;
else
spanError.innerHTML = "";
}
What is the proper way to make a function and give it a regex like a parameter?
The regexp is passed fine, these two lines are erranous instead:
var field = form.getElementById(idField);
var spanError = form.getElementById(idError);
getElementById() is a method of document only. You can fix the issue by using id string like below:
var field = form[idField];
var spanError = form[idError];
... or using getElementById(): var field = document.getElementById(idField);
Also this line (unless a typo in the post)
if(!regex.test(idField.value))
should be:
if(!regex.test(field.value))