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 have a question I tried to pass a jquery variable to php but when I look in console I got an error:
SyntaxError: missing ) after argument list):.append('Edit') and I don't understand where is the problem
var items=[];
var link = "<?php echo base_url()?>firm/editFirm/";
$.each(obj, function(i,val)
{
$('#finalResult').text("Results");
items.push($('<li/>').text
(
val.name_firm + "---" +
val.idno+"---" +
val.adresa+ "---" +
val.cont_banca+ "---" +
val.swit+ "---" +
val.banc_name+"---"
).append("<a href='"link+val.idno"'>Edit</a>")
);
});
Help me please.
You've missed the concatenation in the last bit:
append("<a href='"link+val.idno"'>Edit</a>")
Should be
append("<a href='" + link + val.idno + "'>Edit</a>")
I hope you aren't calling the php inside a .js file. I find it's cleaner to retrieve server-side variables using data-attributes inside DOM elements.
In the case of storing URLs for your use in Javascript, I'm really fond of the localize_script function of Wordpress, you just render the variables in a tag in the header or footer via PHP and you have them all available in a nicely separated place.
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 5 years ago.
Improve this question
I am modifying a code example that I will use (and not very familiar with Javascript)
This is the piece of code
function chk() { cnt++;
var resp=ajax('chk.php', 'POST', 'ordernr='XXXXXX'&r='+((new Date()).getTime()));
if (resp=='3') {
I am posting to this file withe a Querystring-varaible named ordenr
What is the correct syntax to enter the value of Querystring.ordernr instead of XXXXXX
var orderNumber = 1;
var requestParamsStr = 'ordernr=\'' + orderNumber + '\'&r=' + ((new Date()).getTime());
console.log(requestParamsStr);
function chk() {
//cnt++;
var resp = ajax('chk.php', 'POST', encodeURIComponent(requestParamsStr));
//rest of code
}
I think I understand your question. If you need to put quotes around the order number then you must use the escape character / the way I'm doing in the code snippet, so that it doesn't delimit the string (or, alternatively, you could use double quotes within the single quotes). You must also use + to concatenate the the strings.
UPDATE:
I've encoded the request param string as per #ADyson's comment.
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 trying to embed an image in a div. The source of the image is dynamic which is stored in the attribute 'weatherIconURL' of the JS Object 'storeLocations'. That is for each storeLocation I am trying to show the corresponding weatherIcon image. Below is the code I am using
var block = '<div>'+'<p><b>'+storeLocations[i].accountName+'</b></p>'+
'<p>Min Temp: '+storeLocations[i].minTemp+'</p>'+
'<p>Max Temp: '+storeLocations[i].maxTemp+'</p>'+
'<img src="storeLocations[i].weatherIconURL"/>'+
'</div>';
The image is not getting displayed. I have tried using escape character as well.
You're not including the variable in the string the same way you are all the others. Notice the difference? This should fix you up:
var block = '<div>'+'<p><b>'+storeLocations[i].accountName+'</b></p>'+
'<p>Min Temp: '+storeLocations[i].minTemp+'</p>'+
'<p>Max Temp: '+storeLocations[i].maxTemp+'</p>'+
'<img src="' + storeLocations[i].weatherIconURL + '"/>'+
'</div>';
Syntax highlighting (like that used here on SO) should make this stand out to a simple visual inspection.
why are you using concatinate so much simply add this code
var block = '<div><p><b>'+storeLocations[i].accountName+'</b></p><p>Min Temp: '+storeLocations[i].minTemp+'</p><p>Max Temp: '+storeLocations[i].maxTemp+'</p><img src='+storeLocations[i].weatherIconURL+'/></div>';
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 + "']")
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;
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 trying to replace the src of an tag with another path. This works perfectly well:
var tempDocId = 'someId';
$('#documents' + that.ticketId).append('<img id="'+tempDocId+'" src="/img/support/pdf_icon.jpg">');
but the following code gives one of those "image not found" icons ():
var tempDocId = 'someId';
$('#documents' + that.ticketId).append('<img id="'+tempDocId+'" src="/img/support/loading.jpg">');
$('#tempDocId').attr("src", "/img/support/pdf_icon.jpg");
Does anybody know what I'm doing wrong here? All tips are welcome!
because you are looking for id="tempDocId", not the one you generated.
$('#tempDocId').attr("src", "/img/support/pdf_icon.jpg");
needs to be
$('#' + tempDocId).attr("src", "/img/support/pdf_icon.jpg");
so you are not replacing the source. My guess is that your loading image is not valid.
Because $('#tempDocId') doesn't exist. tempDocId is a variable, so try:
$('#' + tempDocId).attr('src', '/img/support/pdf_icon.jpg');
var tempDocId = 'doc' + Math.random().toString().substr(2);
var $img = $('<img id="'+tempDocId+'" src="/img/support/loading.jpg">');
$img.appendTo('#documents' + that.ticketId);
$img.attr('src', '/img/support/pdf_icon.jpg');