Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Feb 2011
    Posts
    8
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Exclamation Using JavaScript to display Alt Text from a search?

    This is a follow up to my older thread, about tables and finding images within them. So after getting some help from "Krupski" I found myself stuck again. I'm trying to go at this rather from an other point of view, instead of getting the cell information I am now trying to get the alt text value. from within the image tag. but being a novice at this well ive hit a wall.

    My code so far. searches though the table finding the sad images then i want it to display the Alt-text or an other value table_id or similar. also is there a fast way of putting in Alt text like A1,2,3 B1,2,3 etc like an automated loop. (might work on this after the main problem is dealt with)

    Code:
    <html>
    
    <head>
    	<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
        }
    	
        function searchFor(){
        findImg('smiley%20sad%20Icon.jpg'); // call the function with the name to be matched
    	}
        </script>
    </head>
    
        <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" Alt="A1"> </td>
            <td Id="2"><img src="http://www.hencam.co.uk/hencam_forum//extensions/Smile/tango/face-smile.png" Alt="A2"> </td>
            <td Id="3"><img src="http://www.iconeasy.com/icon/thumbnails/System/Icons%20for%20Developers/smiley%20sad%20Icon.jpg" Alt="A3"></td>
          </tr>
          <tr Id="B">
            <td Id="1"><img src="http://www.hencam.co.uk/hencam_forum//extensions/Smile/tango/face-smile.png" Alt="B1"></td>
            <td Id="2"><img src="http://www.iconeasy.com/icon/thumbnails/System/Icons%20for%20Developers/smiley%20sad%20Icon.jpg" Alt="B2"></td>
            <td Id="3"><img src="http://www.hencam.co.uk/hencam_forum//extensions/Smile/tango/face-smile.png" Alt="B3"></td>
          </tr>
          <tr Id="C">
            <td Id="1"><img src="http://www.hencam.co.uk/hencam_forum//extensions/Smile/tango/face-smile.png" Alt="C1"></td>
            <td Id="2"><img src="http://www.hencam.co.uk/hencam_forum//extensions/Smile/tango/face-smile.png" Alt="C2"></td>
            <td Id="3"><img src="http://www.hencam.co.uk/hencam_forum//extensions/Smile/tango/face-smile.png" Alt="C3"></td>
          </tr>
        </table>
        <br>
        <input type="button" value="Search" id="Search" onClick="searchFor();"/>
        </body>
        </html>
    Thanks in advance anyone who can help.

    ~Mark j

  • #2
    Banned
    Join Date
    Feb 2011
    Posts
    2,699
    Thanks
    13
    Thanked 395 Times in 395 Posts
    I am now trying to get the alt text value. from within the image tag. but being a novice at this well ive hit a wall
    If you wrote all that code yourself, you can't be a total novice

    Anyway, if I understand you correctly, all you need to do is loop through the e nodelist and store the value in the alt property in each img in e in a variable and then do whatever you need with it.

  • #3
    New to the CF scene
    Join Date
    Feb 2011
    Posts
    8
    Thanks
    4
    Thanked 0 Times in 0 Posts
    I didn't write the code myself got some help from Krupski. as far as JavaScript goes I'm a novice Coder I come from a C# Background and even at that it was mostly basic stuff loops and what not. If you could explain further i would appreciate it a lot.

    ~Mark j


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •