How to pass value for the JavaScript statements? [closed] - javascript

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 want to pass a value to a Javascript Statement. Is it possible?
For Example :
function Show(msg, Id, Msgtype) { // I need to pass this Id argument to below javascript innerHtml statement
var strVar = "";
strVar = "Hello" + Msgtype + " <i class='icon-remove close'></i> " + msg + "</div>";
document.getElementById("???").innerHTML = strVar; // ??? should be the Id above in the function arguments
}
Or in other way, how can I achieve this scenario?

Just pass Id, like this
document.getElementById(Id).innerHTML = strVar;

Related

JavaScript For-Loop Question: Why Am I getting a syntax error? [closed]

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 am working through Javascript for Kids, which is a surprisingly fun little book for a beginner, but I'm having trouble testing a For Loop example in the text:
var sheepCounted = 0;
for (var sheepCounted = 0; sheepCounted < 10; sheepCounted++) {
console.log(“I have counted” + sheepCounted + “sheep!”);
}
console.log(sheepCounted);
When I use a Javascript tester to test this example I get a syntax error, but I'm not sure why? Can anyone help me out? Thanks.
Change this line which uses “ ”:
console.log(“I have counted” + sheepCounted + “sheep!”);
To this with " ":
console.log("I have counted" + sheepCounted + "sheep!");

Javascript backgroundColor works on some computers, not on others? [closed]

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 6 years ago.
Improve this question
This part of javascript code works on my home computer, but doesn't at work. Also, my colleague tested it and it doesn't work on her home computer?!
function klikNaX(x, y, z) {
var u = document.getElementById(z);
var u2;
u2 = u.style.backgroundColor;
document.getElementById("test").innerHTML = (z + " " + u2);
}
The problem seems to be with this part
u.style.backgroundColor;
Its not a problem of style.backgroundColor, instead please check if 'u' is a valid node and not undefined.
And try setting a color to u.style.backgroundColor = 'green'

SyntaxError: missing ) after argument list var x = $("input[name="+value+'[]'"]") [closed]

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 6 years ago.
Improve this question
I am getting error on this. i don't know what happen here.
enter code here
$(".addCategory").on('click',function(){
var value= $(".getvalue").val();
var x = $("input[name="+value+'[]'"]")
$(x).each(function(key,val){
if($(val).val().length<=0)
{
alert ("Please fill all the fileds");
}
});
});
You have problem with quotes
var x = $("input[name='" + value + "[]']")
Problem was with your quotes:
replace with following code
$(".addCategory").on('click',function(){
var value= $(".getvalue").val();
var x = $("input[name='"+value+"[]']") // add proper quotes
$(x).each(function(key,val){
if($(val).val().length<=0)
{
alert ("Please fill all the fileds");
}
});
});
See How it should wrap up
var x = $("input[name='"+value+"[]']")

Why url query string doesn't pass a variable value? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 6 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 am trying to pass a parameter in query string i.e._type=1 but it doesn't pass. It doesn't appear in URL, other values does but not this one. Why ?
SitePaymentReportByBranch = function () {
$('#btnprintSitePaymentByBranch').on('click', function (e) {
e.preventDefault();
if ($("#form1").validationEngine('validate')) {
var _employerID = "";
if ($('#cmbEmployerSitPaymentByParameter :selected').text() == "-Select-") {
alert('Plz Select Employer');
}
var url = '/Reports/frmSitePayment.aspx?_EmployerID=' + $('#cmbEmployerSitPaymentByParameter :selected').val() + '&_Formdate=' + $("#formdate").val() + '&_Todate=' + $("#todate").val() +'_type=1';
commonStartup.openReportWindow(url);
}
});
},
You missed & before _type fix will be '&_type=1'
var url = '/Reports/frmSitePayment.aspx?_EmployerID=' + $('#cmbEmployerSitPaymentByParameter :selected').val() + '&_Formdate=' + $("#formdate").val() + '&_Todate=' + $("#todate").val() +'&_type=1';
Query parameters must be separated with &. You have omitted this for your _type parameter:
'_type=1'
should be;
'&_type=1'

jquery string not working inside $() [closed]

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 7 years ago.
Improve this question
I have the following jquery function. and i am calling it as below mentioned.
function hideSubArea(area, subArea) {
if ($('#cmdArea').val() == area) {
console.log('hide:' + subArea);
//$(":checkbox[value=peoplebulkinsert]").closest("label").hide();
$(":checkbox[value=subArea]").closest("label").hide();
}
}
And calling it as
hideSubArea('<?php echo CustomType::CF_PEOPLE ?>', '<?php echo CustomType::CF_SUB_PEOPLE_BULK_INSERT ?>');
this way its not working.
also this is not.
hideSubArea('people', 'peoplebulkinsert');
but it works when i directly use as
$(":checkbox[value=peoplebulkinsert]").closest("label").hide();
why this happens with jquery ?
subArea is a variable, not a string in this case. It needs to be concatenated. It should be -
$(":checkbox[value='" + subArea + "']")

Categories

Resources