image swapping - js and webserver portibiltiy

Discussion in 'Javascript' started by uNConVeNtiOnAL, Sep 19, 2003.

  1. Hi -

    I have a page that has a button that makes a prompt appear for the user
    to type input. When they have typed in input, I want the button to
    change
    color when the prompt closes. I am trying to do image swapping

    This snippet will prevent 'null' from appearing initially and
    successfully
    records user changes (typing in a comment)

    var existing = form.elements[type].value;
    if (existing == null) {
    existing = "";
    }
    var comments = prompt("Enter Comment ", existing);
    form.elements[type].value = comments;

    Now my problem. just below the code above I am trying

    alert("document.images[9].src=" + document.images[9].src);
    if (comments == null) {
    document.images[9].src=document.images["images/buttonComments.gif"];
    }
    else {
    document.images[9].src=document.images["images/buttonCommentsPresent.gif"];

    }

    The problem is that the alert shows the address of the image as
    http://localhost:9080/mystuff/images/image1.gif

    and when I swap it out the new image does not show up - a red X

    The images will always be under /images on every server - how can I
    make this code portible without having to hardcode the 'http:etc" ?

    Thanks

    Tom
     
    uNConVeNtiOnAL, Sep 19, 2003
    #1
    1. Advertisements

  2. This is not right. You probably mean:
    document.images[9].src="images/buttonComments.gif";
    (and ditto for the next assignment)

    /L
     
    Lasse Reichstein Nielsen, Sep 19, 2003
    #2
    1. Advertisements

  3. YOU SIR, ARE A GODSEND!!!!

    thanks

    Tom
     
    uNConVeNtiOnAL, Sep 19, 2003
    #3
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.