Why doesn't .attr("src", "/some/path/image.png") work? [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'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');

Related

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'

how to find and replace text url with links in jquery [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
Hi I want to find text url in my editor and convert them to anchor tag links using jquery.
here is my code
function urlify(text) {
var urlRegex = /^(https?:\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)*\/?$/;
return text.replace(urlRegex, function(url) {
return '' + url + '';
})
}
$("#queEditor").bind('input propertychange', function(){
var url = urlify($("#queEditor").text);
console.log(url);
});
But it's giving an error undefined function text. Could someone help me rectify this?
Since .text() is a function you need to use () when you want to invoke it.
$("#queEditor").text(); //Notice ()

Pass jquery variable to php [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 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.

Categories

Resources