I'm new to Jscript but trying to combien it with CSS to build a website. I need to do the following:
1) Read the img src property in the mainPicture DIV
2) Replace a string in the actual name of the image
3) Store the new result and pathname
The code I have so far is this:
function getPic(){
var currentPicture = document.getElementById("mainPicture").getElementsByTagName("img")[0].src;
alert(currentPicture);
}
This works well for part 1, but gives me the path of the image *relative* to the Document vs. the Site Root (C:/website/me/images/pic1_before.jpg instead of /images/pic1_before.jpg). I need to get the Site Root path.
For part 2, what code do I write to take the string pic1_before.jpg and change it to pic1_after.jpg?
For part 3, how do I then save the whole string /images/pic1_after.jpg? I will be applying it somewhere else.
Hope this makes sense and thanks in advance for helping.
function getPic() {
document.getElementById("mainPicture").src;
window.alert(currentPicture);
}
If the img tag has id="mainPicture"
That doesn't work for me. When I do a mouseDown on my image that calls the getPic function, the alert box gives me the info I need with my code, but not with the one above.
To change:
Code:
function changePic() {
document.getElementById("mainPicture").src = '/images/pic1_after.jpg';
}
[/QUOTE]
I need to run some code to actually find/change the name of the jpg, dynamically, not statically like above, because the mainPicture DIV may be holding an image called pic1_after.jpg or pic3_after.jpg...anywhere up to 60! That's why I need to do this dynamically, hence my post.
Any more help you could provide though would be helpful.
Bookmarks