473,387 Members | 1,844 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 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 5729
"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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.