Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 02-22-2011, 03:18 PM   PM User | #1
markscotland
New to the CF scene

 
Join Date: Feb 2011
Posts: 8
Thanks: 4
Thanked 0 Times in 0 Posts
markscotland is an unknown quantity at this point
Exclamation Using JavaScript to write location of an image within a table?

Is it possible to use JavaScript to locate all of the "smiley sad Icon.jpg"'s and output the location within the table?

Such as A3, and B2.

Thank you in advance.

Code:
<html>
<body>
<table width="200" border="1">
  <tr Id="A">
    <td Id="1"><img src="http://www.hencam.co.uk/hencam_forum//extensions/Smile/tango/face-smile.png"> </td>
    <td Id="2"><img src="http://www.hencam.co.uk/hencam_forum//extensions/Smile/tango/face-smile.png"></td>
    <td Id="3"><img src="http://www.iconeasy.com/icon/thumbnails/System/Icons%20for%20Developers/smiley%20sad%20Icon.jpg"></td>
  </tr>
  <tr Id="B">
    <td Id="1"><img src="http://www.hencam.co.uk/hencam_forum//extensions/Smile/tango/face-smile.png"></td>
    <td Id="2"><img src="http://www.iconeasy.com/icon/thumbnails/System/Icons%20for%20Developers/smiley%20sad%20Icon.jpg"></td>
    <td Id="3"><img src="http://www.hencam.co.uk/hencam_forum//extensions/Smile/tango/face-smile.png"></td>
  </tr>
  <tr Id="C">
    <td Id="1"><img src="http://www.hencam.co.uk/hencam_forum//extensions/Smile/tango/face-smile.png"></td>
    <td Id="2"><img src="http://www.hencam.co.uk/hencam_forum//extensions/Smile/tango/face-smile.png"></td>
    <td Id="3"><img src="http://www.hencam.co.uk/hencam_forum//extensions/Smile/tango/face-smile.png"></td>
  </tr>
</table>

</body>
</html>
markscotland is offline   Reply With Quote
Old 02-22-2011, 05:08 PM   PM User | #2
Krupski
Regular Coder

 
Krupski's Avatar
 
Join Date: Dec 2010
Location: United States of America
Posts: 502
Thanks: 39
Thanked 47 Times in 46 Posts
Krupski is on a distinguished road
Quote:
Originally Posted by markscotland View Post
Is it possible to use JavaScript to locate all of the "smiley sad Icon.jpg"'s and output the location within the table?

Such as A3, and B2.

Thank you in advance.
Making a WGET script, huh?

This should get you started:

Code:
<script type="text/javascript">
var findImg = function(name) {
    var e = document.getElementsByTagName('img');
    var i = e.length; // how many img elements total
    var str = ''; 
    while (i--) {
        if (e[i].src.indexOf(name) != -1) // if match...
        str += e[i].src + '\n'; //...copy to str with a newline
    }
    alert(str); // display all matches
}

findImg('smiley%20sad%20Icon.jpg'); // call the function with the name to be matched

</script>
All this does is find anything which matches the input to the function and pops it up in an alert window. But all the stuff is there so get you started.

You may want to stick something like .toLowerCase() on the search string and the filename strings so that they match the name even if the case doesn't match.

Have fun.....

-- Roger
__________________
"Anything that is complex is not useful and anything that is useful is simple. This has been my whole life's motto." -- Mikhail T. Kalashnikov
Krupski is offline   Reply With Quote
Users who have thanked Krupski for this post:
markscotland (02-22-2011)
Old 02-22-2011, 05:26 PM   PM User | #3
markscotland
New to the CF scene

 
Join Date: Feb 2011
Posts: 8
Thanks: 4
Thanked 0 Times in 0 Posts
markscotland is an unknown quantity at this point
Quote:
Code:
<script type="text/javascript">
var findImg = function(name) {
    var e = document.getElementsByTagName('img');
    var i = e.length; // how many img elements total
    var str = ''; 
    while (i--) {
        if (e[i].src.indexOf(name) != -1) // if match...
        str += e[i].src + '\n'; //...copy to str with a newline
    }
    alert(str); // display all matches
}

findImg('smiley%20sad%20Icon.jpg'); // call the function with the name to be matched

</script>
After Trying to get my head around this, it doesn't seem to add the new lines to the output or anything for that matter. I thought there would be a JavaScript command to export the location of each cell the image was contained within. Novice at coding on W3schools atm looking up too much of everything else but what I need

~EDIT

Got it displaying the names of each image
Now to work out how to display the cell its in.

Last edited by markscotland; 02-22-2011 at 05:31 PM.. Reason: update
markscotland is offline   Reply With Quote
Reply

Bookmarks

Tags
image, javascript, location, table, write

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 05:38 PM.


Advertisement
Log in to turn off these ads.