Reputation: 4332
Hi guys I have made a JqueryUI simple slider,on certain value range I make Image URL and then try to change src attribute.
There are four images I'm trying to change.
Check the jsFiddle here.
I think the code is fine but its not working ,I dont know why ?
Upvotes: 0
Views: 6949
Reputation: 523
Try this
$("#postRetrmntImage").attr('src', 'newimage.png');
Upvotes: 0
Reputation: 35572
assign a value to postRetrmntImage
then use prop
instead of attr
see why prop
var postRetrmntImage="postRetrmntImage";
$("#" + postRetrmntImage).prop('src', ImageName );
Upvotes: 1
Reputation: 7355
Trying doing this:
$("#" + postRetrmntImage.toString()).attr('src', ImageName );
Upvotes: 2
Reputation: 34107
demo http://jsfiddle.net/8Sw5J/
Explanation: Please use this: $("#" + sliderId).prop('src', ImageName );
since in your function you are passing the id as sliderId.
Also If I may suggest use .prop
good read here: .prop() vs .attr()
Rest demo you can see how it works,
Hope this helps :)
full code
$(document).ready(function () {
makeSingleSliderWithImage('postRetrmntMnthlyPaymt', 0, 10000, 0, 500);
}
);
function makeSingleSliderWithImage(sliderId, minimum, maximum, val, steps) {
//Display label shud have a X appended
$('#' + sliderId).slider(
{
//range: 'min',
min: minimum,
max: maximum,
step: steps,
//starting values for silders
value: val,
slide: function (event, ui) {
//var ImageURL = "Images/";
//var ImageName = "";
//var ext = ".jpg";
if ((ui.value >= 0) && (ui.value <= 2000))//Basic: 0-2000
ImageName = "http://www.iconempire.com/icon-processor/icon40.gif";
else if ((ui.value >= 2500) && (ui.value <= 4500))//Moderate: 2500-4500
ImageName = "http://aux.iconpedia.net/uploads/14234829766434728.png";
else if ((ui.value >= 5000) && (ui.value <= 7000))//Comfortable: 5000-7000
ImageName = "http://www.iconempire.com/icon-processor/icon40.gif";
else if ((ui.value >= 7500) && (ui.value <= 10000))//Luxury:7500-10,000
ImageName = "Luxury";
//var fullURL = ImageURL + ImageName + ext;
//change Image URL
$("#" + sliderId).prop('src', ImageName ); //{ src: fullURL });
alert($("#" + sliderId).prop('src'));
//change Slider Value
$("#" + sliderId + "X").text(ui.value);
}
}
);
}
Upvotes: 2
Reputation: 2583
Change line...
$("#" + postRetrmntImage).attr('src', ImageName );
to...
$("#postRetrmntImage").attr('src', ImageName );
Upvotes: 1