www.webdeveloper.com
Results 1 to 3 of 3

Thread: [RESOLVED] Help creating <A> with IMG=

  1. #1
    Join Date
    Mar 2009
    Location
    Florida
    Posts
    7

    resolved [RESOLVED] Help creating <A> with IMG=

    I'm stumped. I've googled this until I lost consciousness and cannot find an answer. I'm trying to write a specific anchor/link depending upon the option selected from a drop-down list. The link from the image is to a pdf file. Can someone point me in the right direction?

    Here is my code:

    Code:
    <script type="text/javascript">
    function getScorecard(sel)
    {
    
    //create the scorecard node
    var myA=document.createElement("A");
    var myImg=document.createElement("IMG");
    var url = "http://14holegolf.googlepages.com/Birecree-Contestable.pdf";
    
    myA.setAttribute("href",url);
    
    //create the image node
    url = "http://14holegolf.googlepages.com/Birecree-Contestable.jpg";
    var myImg=document.createElement("IMG");
    myImg.setAttribute("src",url);
    
    // Append the image node to the anchor
    myA.setAttribute("img", myImg);
    
    document.getElementById('targetDiv').appendChild(myA);
    
    
    }
    </script>
    HTML Code:
     <form action="" method="post">
     	<table align="center" border="0" cellpadding="8" width="680">
     		<tbody>
     			<tr>
     				<td align="right"><b>Team:</b></td>
     				<td align="left"><select name="team" onchange="getScorecard(this)">
     					<option value="" selected>Select a team</option>
     					<option value="1">Option 1</option>
     					<option value="2">Option 2</option>
    					</select>
    				</td>
    			</tr>
    			<tr>
    				<td colspan="3" <div id="targetDiv"></div>
    				</td>
    			</tr>
    		</tbody>
    	</table>
    </form>
    Last edited by TheBearMay; 03-13-2009 at 10:20 AM.

  2. #2
    Join Date
    Nov 2003
    Location
    Worthington, OH, USA
    Posts
    3,634
    <img> is not an attribute of <a>, so append the image to the anchor:

    Code:
    <script type="text/javascript">
    
    function getScorecard(sel)
    {
    
    //create the scorecard node
    var myA=document.createElement("A");
    var myImg=document.createElement("IMG");
    var url = "http://14holegolf.googlepages.com/Birecree-Contestable.pdf";
    
    myA.setAttribute("href",url);
    
    //create the image node
    url = "http://14holegolf.googlepages.com/Birecree-Contestable.jpg";
    var myImg=document.createElement("IMG");
    myImg.setAttribute("src",url);
    
    // Append the image node to the anchor
    myA.appendChild(myImg);
    
    
    document.getElementById('targetDiv').appendChild(myA);
    
    
    }
    </script>
    54 68 65 42 65 61 72 4D 61 79

  3. #3
    Join Date
    Mar 2009
    Location
    Florida
    Posts
    7

    Fixed.....

    That did the trick. I was killing myself over this simple thing...

    Thanks You.... Thank You.... Thank You....

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles