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 4 of 4
  1. #1
    New Coder
    Join Date
    Jul 2004
    Posts
    17
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Changing the src attribute of an image

    Hi,
    I am trying to change the src attribute of an image, is there any way of doing so by passing in the id of the image to a function as follows

    function ChangeImage(image_id)
    {
    document.getElementByID(image_id).src = "\images\hello.gif"
    }//end of function

    <img id="hello" src= "\images\bye.gif">

    is that possible, I am aware of the document.images collection but I would prefer refering to the image using an id I provided, instead of looping through values.
    I have another question to ask, I have two iframes (frame1,frame2) on a document, the links are on the left hand side on frame1 while the page's content is on frame2, I would like to change the iframes src attribute when the links on frame1 are clicked how can I do that?
    Thanks
    Bob

  • #2
    Banned
    Join Date
    Sep 2003
    Posts
    3,620
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Did you even try the code you posted?
    Because from what I seen, it should work but I do not understand what you mean by looping thru the images collection. There is no need to loop if you pass the image name thru the function as you are with your id. This would have the added benifit of being backward compatable with browsers which do not support getElementById....

    function ChangeImage(image_id)
    {
    document.images[image_id].src = "\images\hello.gif"
    }//end of function

    <img name="hello" src= "\images\bye.gif">

    2) document.frames['frame2'].location.href = 'myNewSource.html';

    .....Willy

  • #3
    New Coder
    Join Date
    Jul 2004
    Posts
    17
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Passing arguments into Javascript function from asp.net code

    Hi,
    I am dynamically creating a table that contains links and images in my asp.net code as follows

    sub page_load(sender, event_args)
    {
    Dim record_set As System.Data.SqlClient.SqlDataReader
    record_set = command.ExecuteReader
    Dim strBuilder As System.Text.StringBuilder

    strBuilder.Append("<Table cellspacing= cellpadding>")
    strBuilder.Append("<tr><td>")
    strBuilder.Append("<a href= ' "& record_set.GetString("URL_LOCATION") &" ' onmouse = 'changeLinkColor( "& strLinkID&" )' id =' hello_name '>")

    strBuilder.Append(" Google ")
    strBuilder.Append("</a>")

    literal_html_component_accessible_in_asp.InnerHtml = strBuilder.ToString()


    }//end of page_load


    my javascript code is
    <script language="Javascript">

    function changeLinkColor(link_ID)
    {
    document.getElementByID(link_ID).style.Color="ffff00"

    }//end of function
    </script>

    for some bizzare reason when I pass in the argument link_ID into the javascript function is value isn't what its supposed to be, can anyone spot something wrong with my code syntax??
    Thanks Bob

  • #4
    Regular Coder
    Join Date
    Aug 2002
    Location
    USA
    Posts
    625
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I am trying to change the src attribute of an image, is there any way of doing so by passing in the id of the image to a function as follows

    function ChangeImage(image_id)
    {
    document.getElementByID(image_id).src = "\images\hello.gif"
    }//end of function

    <img id="hello" src= "\images\bye.gif">



    What happend to the thread topic...?




    <script>
    <!--

    function chImg(imgName){
    document.images[imgName].src = "images/whatever2.gif"
    }

    //-->
    </script>



    <a href="javascript:chImg('whatever');void(0);"><img name="whatever" border="0" width="50" height="50" src="images/whatever1.gif" /></a>


    or

    <script>
    <!--

    function chImg(imgNum){
    document.images[imgNum].src = "images/whatever2.gif"
    }

    //-->
    </script>



    <a href="javascript:chImg(0);void(0);"><img name="whatever" border="0" width="50" height="50" src="images/whatever1.gif" /></a>





    -james
    "God so loved the world that he gave his only begotten son, so that whosoever believed in him would not perish, but have everlasting life. For God did not send his son into the world to condemn the world, but so that through him the world might be saved. "


  •  

    Posting Permissions

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