javascript onclick get image name without path -
i need copy name of image (name + extension) src attribute without path.. html:
<input type="text" id="result" /><br /><br /> <img src="../some_folder/some_folder/photo_name.jpg" onclick="getname()" id="img1" />
js:
function getname() { document.getelementbyid("result").value = document.getelementbyid("img1").src; }
this code clones full path of image.. path not static, can not cut rest of "src".. in advance
you should try code:
var filename = fullpath.replace(/^.*[\\\/]/, '');
your js function be:
function getname() { var fullpath = document.getelementbyid("img1").src; var filename = fullpath.replace(/^.*[\\\/]/, ''); // or, try this, // var filename = fullpath.split("/").pop(); document.getelementbyid("result").value = filename; }
Comments
Post a Comment