#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2003
    Posts
    22
    Rep Power
    0

    Retrieve variable's value between javascript and asp


    I submit my problem as I think it is possible to resolve but I don't find the way to the answer !!

    I have an ASP file in which I declare some images :

    <IMG NAME="zoom" VALUE="" onClick=changeImage(document.images[0].name);>
    <IMG NAME="pan" VALUE="" onClick=changeImage(document.images[0].name);>

    Firstly : I'd like to change the value of the image which has been clicked. But in the Javascript function named changeImage, :
    'document.images[0].value' stays 'undefined' (even though I put some non-empty string in VALUE="")
    So, how could I retrieve the value of images !!!

    Secondly : Once the value of the selected image has been changed, I'd like to be able in the asp file to retrieve the value of the images too. Applying :
    Dim str
    str = document.images[i].value
    ====> doesn't work

    So : If you've got a good experience in javascript and asp, and have any idea of answer, please, take a few seconds, write a thread to put me in the right way
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2003
    Location
    Canada, Quebec, Montreal
    Posts
    410
    Rep Power
    12
    The first thing you need to understand is the difference between Client Side script and Server Side script.

    Client Side script is executed/interpreted by *YOUR* browser.

    Server Side script is executed/interpreted by the *SERVER*.

    Now, assuming that the *SERVER* is in HongKong and that, you the client, is on an airplane overseas with your laptop.

    In order for something to happen on the *SERVER* the user must click or do something, in other words some sort of event must be triggered so that your browser makes a request to the *SERVER* in HongKong.

    Now, let's get back to your problem...

    My first question is:
    You are using the <img> tag, but I don't see the src attribute. Shouldn't you have something like:

    <img src="images/myimage.gif" width="15" height="15">

    NOTE: I've assumed that you had an image called myimage.gif and that it was stored inside a folder called images.


    Another thing, I've never used the onclick attribute of the <img> tag, why? because....I've always embedded my <img> tag between an <a href="">...</a> tag when I wanted an image to be clickable.

    Try this:

    <a href="javascript:changeImage()"><img src="..." width="..." height="..." border="0"></a>

    Fill in the ... with what you have.

    IMPORTANT:
    Make sure your <img's> are nested between a <form> and a </form> tag


    Now inside the javascript changeImage() function try some debugging, for example:

    function changeImage()
    {
    alert(document.images[0].name)
    }

    Notice that I haven't passed anything(no parameters) inside the changeImage() function but you could always try something different such as:

    <a href="javascript:changeImage('myimage.gif')"><img src="..." width="..." height="..." border="0"></a>

    Then the javascript:

    function changeImage(imageName)
    {
    alert(imageName)
    }

    That should work...so I think ;-)


    Now for the ASP part, you realize that you'll need some sort of "event" happening so that you can retrieve what ever you want to retrieve right?

    What you can do(and that is only a suggestion) is to add code inside the changeImage() function so that it looks like this:

    function changeImage(imageName)
    {
    //Do whatever needs to be done


    //Then right whatever inside a <hidden> field
    document.frmMain.hidField.value = xxxxxxxxx;
    }

    NOTE: I've assumed that your <form>...</form> name would be called frmMain and that you have a <hidden> field inside that <form>...</form> called hidField.
    The xxxxxxxxx part is whatever you need to be put.

    Now, ideally, the user should submit your <form>...</form>

    Only then will you be able to do something like:

    <%
    Dim strWhatever

    strWhatever = Trim(Request.Form("hidField"))

    'FOR DEBUGG ONLY
    'Response.Write "-->" & strWhatever & "<--"
    'Response.End
    %>


    Hope this helps!
    Sincerely

    Vlince

    PS: I realize that I may NOT have answered your question directly but I still hope it did help you out ;-)

IMN logo majestic logo threadwatch logo seochat tools logo