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 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Feb 2006
    Location
    Bath UK
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Problems re using a line of HTML

    I wish to change a prototype web page which currently uses 15 lines of HTML to display 15 photos into one which displays 15 photos by reusing a single line of HTML.
    The relevant part of my initial attempt is shown below.
    The first part of the while loop successfully puts the filename into the HTML line.
    But I cannot get the string held in shortdes to be used in place of Photo title or the string held in style to be used in place of s1.

    Any assistance would be gratefully received.
    Many thanks

    <body>
    <img name="gallery" src="blank.jpg" alt="Photo title" div class="s1">

    <script>
    count=1
    while (count<6)
    {
    function change(jpgName,desc,styleName)
    {
    var filename=jpgName.toString()+".jpg"
    document.gallery.src=filename

    var shortdes=desc.toString()
    document.gallery.alt=shortdes

    var style=styleName.toString()
    document.gallery.div=style
    }

  • #2
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    Where are jpgName, desc, and styleName coming from?
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #3
    New to the CF scene
    Join Date
    Feb 2006
    Location
    Bath UK
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks for your response.
    jpgName, desc, and styleName are being read from arrays set up in the head.
    I have used Alert to check that filename, shortdes and style contain the required strings. I just don't understand why filename is substituted correctly and shortdes and style are not.

  • #4
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    Try this
    Code:
    var count = 1
    while (count < 6)
    {
    	function change(jpgName,desc,styleName)
    	{
    		var el = document.images['gallery'];
    		var filename = jpgName.toString()+".jpg"
    		el.setAttribute('src',filename);
    		
    		var shortdes = desc.toString()
    		el.setAttribute('alt',shortdes);
    		
    		var style1 = styleName.toString()
    		el.className = style1;
    	}
    }
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #5
    New to the CF scene
    Join Date
    Feb 2006
    Location
    Bath UK
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    This is perfect.
    Very many thanks for your speedy solution to this problem.
    Vito B


  •  

    Posting Permissions

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