OnChange Event Problem - Please Help

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Lee Mundie

    OnChange Event Problem - Please Help

    Hi there,
    Simple problem here but can't seem to fix it!

    Okay, I have a select list from which people choose avatars...

    the list is option values ie. <option>Worm</option> <option>Frog</option>
    etc etc and is in an include file...
    where the word i.e. worm sources the image ..images/worm.gif - simple so
    far...

    okay main problem is the onChange event in the select tag... which when you
    select a new avatar on the list, the image preview should update... but it
    doesn't
    works on my DB update and refresh, but want it to preview as they select it
    before update.


    Anyone help

    Thanks in Advance

    Lee


    <select name="SelectAva tar" class="avatar" onChange="(avat ar.src =
    SelectAvatar.op tions[SelectAvatar.se lectedIndex].value) &&
    (oldAvatar.valu e='')">

    <option value="<% = strAvatar %>"><% If strAvatar = "" Then Response.Write
    "None Selected" Else Response.Write strAvatar %></option>
    <!-- #include file="forum/selectavatar.as p" -->
    </select>

    <img src="shared/avatars/<%

    'If there is an avatar then display it
    If strAvatar <> "" Then
    Response.Write( strAvatar)
    Else
    Response.Write( "noneselect ed")
    End If
    %>.gif" width="32" height="32" name="avatar">

    <input type="hidden" name="oldAvatar " value="<% = strAvatar %>">


  • Lasse Reichstein Nielsen

    #2
    Re: OnChange Event Problem - Please Help

    "Lee Mundie" <lee.j.mundie@n tlworld.com> writes:
    [color=blue]
    > the list is option values ie. <option>Worm</option> <option>Frog</option>[/color]
    [color=blue]
    > <select name="SelectAva tar" class="avatar" onChange="(avat ar.src =
    > SelectAvatar.op tions[SelectAvatar.se lectedIndex].value) &&
    > (oldAvatar.valu e='')">[/color]

    Your options don't have values. Try this onchange attribute:
    onchange = "document.image s['avatar'].src =
    this.options[this.selectedIn dex].text;
    this.form.eleme nts['oldAvatar'].value = '';"

    It should even work in Mozilla, which your code didn't.

    (Server-side code is not relevant here. Next time, please show us
    the generated code without the ASP)

    /L
    --
    Lasse Reichstein Nielsen - lrn@hotpop.com
    DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
    'Faith without judgement merely degrades the spirit divine.'

    Comment

    • Stuart Palmer

      #3
      Re: OnChange Event Problem - Please Help

      <form name="test">
      <select name="SelectAva tar" class="avatar" onChange="(test .avatar.src =
      test.SelectAvat ar.options[test.SelectAvat ar.selectedInde x].value);(oldAva tar
      ..value=''); alert(test.oldA vatar.value); alert(test.avat ar.src);">

      <option value="1">1</option>
      <option value="2">2</option>
      <option value="3">3</option>
      </select>

      <img src="shared/avatars/name.gif" width="32" height="32" name="avatar">


      <input type="hidden" name="oldAvatar " value="">
      </form>

      Seems to work for me, I don't get what you were trying o do with the &&
      (this is a comarison call in iff statements etc). I have set some alerts to
      show you values of fields for you.

      Hope this helps.

      Stu


      "Lee Mundie" <lee.j.mundie@n tlworld.com> wrote in message
      news:j7Iub.1006 7$o97.4025970@n ewsfep2-win.server.ntli .net...[color=blue]
      > Hi there,
      > Simple problem here but can't seem to fix it!
      >
      > Okay, I have a select list from which people choose avatars...
      >
      > the list is option values ie. <option>Worm</option> <option>Frog</option>
      > etc etc and is in an include file...
      > where the word i.e. worm sources the image ..images/worm.gif - simple so
      > far...
      >
      > okay main problem is the onChange event in the select tag... which when[/color]
      you[color=blue]
      > select a new avatar on the list, the image preview should update... but it
      > doesn't
      > works on my DB update and refresh, but want it to preview as they select[/color]
      it[color=blue]
      > before update.
      >
      >
      > Anyone help
      >
      > Thanks in Advance
      >
      > Lee
      >
      >
      > <select name="SelectAva tar" class="avatar" onChange="(avat ar.src =
      > SelectAvatar.op tions[SelectAvatar.se lectedIndex].value) &&
      > (oldAvatar.valu e='')">
      >
      > <option value="<% = strAvatar %>"><% If strAvatar = "" Then Response.Write
      > "None Selected" Else Response.Write strAvatar %></option>
      > <!-- #include file="forum/selectavatar.as p" -->
      > </select>
      >
      > <img src="shared/avatars/<%
      >
      > 'If there is an avatar then display it
      > If strAvatar <> "" Then
      > Response.Write( strAvatar)
      > Else
      > Response.Write( "noneselect ed")
      > End If
      > %>.gif" width="32" height="32" name="avatar">
      >
      > <input type="hidden" name="oldAvatar " value="<% = strAvatar %>">
      >
      >[/color]


      Comment

      • Richard Cornford

        #4
        Re: OnChange Event Problem - Please Help

        "Lee Mundie" <lee.j.mundie@n tlworld.com> wrote in message
        news:j7Iub.1006 7$o97.4025970@n ewsfep2-win.server.ntli .net...[color=blue]
        > Hi there,
        > Simple problem here but can't seem to fix it!
        >
        > Okay, I have a select list from which people choose avatars...[/color]

        I have read this before recently haven't I? Of course I stopped reading
        that message at about this point because it was HTML on a text only
        newsgroup.
        [color=blue]
        >the list is option values ie. <option>Worm</option>
        ><option>Frog </option> etc etc and is in an include file...[/color]

        Include file? I see no include file. But if the option elements take
        that form then they have no value attributes and so may have no value
        properties.
        [color=blue]
        >where the word i.e. worm sources the image ..images/worm.gif -
        >simple so far...
        >[/color]
        <snip>>[color=blue]
        >
        ><select name="SelectAva tar" class="avatar"
        >onChange="(ava tar.src =
        >SelectAvatar.o ptions[SelectAvatar.se lectedIndex].value) &&
        >(oldAvatar.val ue='')">[/color]

        Assuming your description of the option elements above is inaccurate and
        they do indeed have a value attribute, these property accessors are not
        very cross browser. They will work on a lot of browsers but could also
        work on many others. In the internally generated function (which is
        based on taking the onchange attribute string and using that as the
        function body) the - this - keyword refers to the select element because
        the onchange function is a method of that object, so - this - could (and
        should) be used in place of - SelectAvatar -

        this.options[this.selectedIn dex].value

        The IMG element with the name "avatar" will not necessarily be resolved
        by the use of its name as an identifier (it’s a guaranteed failure on
        Opera 6 when it is not spoofing IE for example). The broadest support
        for referencing named IMG elements is via the document.images
        collection, ie:-

        document.images['avatar'].src = . . . ;

        The circumstance is similar for - oldAvatar - but because that is a
        hidden input element in the current form it would be best to reference
        that in the form's elements collection. As each form element has a
        property called "form" that refers to the form that contains it and -
        this - refers to a form element (the select) - oldAvatar - can be
        referenced in the form's elements collection with:-

        this.form.eleme nts['oldAvatar'].value = '';
        [color=blue]
        > <option value="<% = strAvatar %>">
        ><% If strAvatar = "" Then Response.Write[/color]

        This is not client-side code. If you have client-side problems it is
        almost always useless to look at the server-side code, you need to view
        the source in the client because that is the code that the browser is
        executing and that is where you will find the errors. And showing server
        side code to someone else without explaining _exactly_ what values are
        likely to be being written into, for example, the above value attribute,
        or the contents of selectavatar.as p makes any comment about possible
        causes of errors pure guesswork. When, looking at the code that is
        arriving at the browser would probably make the problem instantly
        obvious.
        [color=blue]
        >"None Selected" Else Response.Write strAvatar %></option>
        > <!-- #include file="forum/selectavatar.as p" -->
        > </select>
        >
        > <img src="shared/avatars/<%
        >
        > 'If there is an avatar then display it
        > If strAvatar <> "" Then
        > Response.Write( strAvatar)
        > Else
        > Response.Write( "noneselect ed")
        > End If
        > %>.gif" width="32" height="32" name="avatar">[/color]
        <snip>

        But here is my guess, above you have written - strAvatar - into a value
        attribute, but here you feel the need to add a dot GIF extension (and a
        path) to that string. However, when you assign the value form the
        selected option to the SRC attribute of the IMG element you are not
        adding a dot GIF extension (or a path). Could it be that without the
        extension (and/or path) the server is failing to find the corresponding
        file and just returning errors?

        Richard.




        Comment

        Working...