472,358 Members | 1,762 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,358 software developers and data experts.

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="SelectAvatar" class="avatar" onChange="(avatar.src =
SelectAvatar.options[SelectAvatar.selectedIndex].value) &&
(oldAvatar.value='')">

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

<img src="shared/avatars/<%

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

<input type="hidden" name="oldAvatar" value="<% = strAvatar %>">
Jul 20 '05 #1
3 5625
"Lee Mundie" <le**********@ntlworld.com> writes:
the list is option values ie. <option>Worm</option> <option>Frog</option> <select name="SelectAvatar" class="avatar" onChange="(avatar.src =
SelectAvatar.options[SelectAvatar.selectedIndex].value) &&
(oldAvatar.value='')">


Your options don't have values. Try this onchange attribute:
onchange = "document.images['avatar'].src =
this.options[this.selectedIndex].text;
this.form.elements['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 - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #2
<form name="test">
<select name="SelectAvatar" class="avatar" onChange="(test.avatar.src =
test.SelectAvatar.options[test.SelectAvatar.selectedIndex].value);(oldAvatar
..value=''); alert(test.oldAvatar.value); alert(test.avatar.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" <le**********@ntlworld.com> wrote in message
news:j7*********************@newsfep2-win.server.ntli.net...
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="SelectAvatar" class="avatar" onChange="(avatar.src =
SelectAvatar.options[SelectAvatar.selectedIndex].value) &&
(oldAvatar.value='')">

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

<img src="shared/avatars/<%

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

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

Jul 20 '05 #3
"Lee Mundie" <le**********@ntlworld.com> wrote in message
news:j7*********************@newsfep2-win.server.ntli.net...
Hi there,
Simple problem here but can't seem to fix it!

Okay, I have a select list from which people choose avatars...
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.
the list is option values ie. <option>Worm</option>
<option>Frog</option> etc etc and is in an include file...
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.
where the word i.e. worm sources the image ..images/worm.gif -
simple so far...
<snip>>
<select name="SelectAvatar" class="avatar"
onChange="(avatar.src =
SelectAvatar.options[SelectAvatar.selectedIndex].value) &&
(oldAvatar.value='')">
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.selectedIndex].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.elements['oldAvatar'].value = '';
<option value="<% = strAvatar %>">
<% If strAvatar = "" Then Response.Write
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.asp 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.
"None Selected" Else Response.Write strAvatar %></option>
<!-- #include file="forum/selectavatar.asp" -->
</select>

<img src="shared/avatars/<%

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

<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.


Jul 20 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: R.G. Vervoort | last post by:
I am using a javafunction (onclick in select) in which i am calling a function in php (thats why i send this to both php and javascript newsgroups). in the onclick i call the function...
4
by: Rick | last post by:
Please Help. I have a tab control with 4 tabs. When a tab is selected, I want to "do stuff". I thought to just do this: Usint the tabControls OnChange event If MyTabControl.Value = 0 then (the...
4
by: Zeebra3 | last post by:
Here goes: I have a web form with several asp:dropdownlists, with which, when selection is changed I want to fire an event defined in some clientside js. The content of the clientside code is...
3
by: jab3 | last post by:
Hello. I"m new to this group, and to JavaScript in general, so please forgive me if I breach local etiquette. I'm trying to implement some client-side 'dynamic' validation on a form. I'm having...
7
by: Peter | last post by:
Does anyone know how to trap SelectedIndexChanged event on the client side for the following control? http://www.metabuilders.com/Tools/ComboBox.aspx I have tried...
5
by: subhodey | last post by:
Hello, I have a ColdFusion online application that has a page having 2 textboxes. Corresponding to these 2 textboxes I have a Custom tag in coldfusion where the textbox is defined by <input...
21
by: Leena P | last post by:
i want to basically take some information for the product and let the user enter the the material required to make this product 1.first page test.php which takes product code and displays...
3
by: lowslyn | last post by:
hi, can someone please help me with javascript... i have this code that checks a text field when the user overrides the value to blank/space. if it is blank/space, i need to change the value...
4
by: xoinki | last post by:
hi all, I am trying to attach an event to onChange property.. the function i am trying to attach is inside a class. for eg.. my js has a structure as follows.. // if not defined a = new...
2
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and efficiency. While initially associated with cryptocurrencies...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was proposed, which integrated multiple engines and...
1
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. header("Location:".$urlback); Is this the right layout the...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific technical details, Gmail likely implements measures...
1
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web server and have made sure to enable curl. I get a...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the synthesis of my design into a bitstream, not the C++...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand. Background colors can be used to highlight important...
0
BLUEPANDA
by: BLUEPANDA | last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS starter kit that's not only easy to use but also...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.