Changing the onclick of an image in aspx file

C

CIndy Lee

I want to change the on click value of an image. Basically the aspx
sets the value of the onclick, after the spot where I want my image.
I need to either set the onlick after (Which didn't work), or declare
the image later and have the HTML put the image somewhere. Maybe I
can do that with divs? (I'm just editing code. I don't want to
change to much. I know i could redo it all with .NET controlls)

<script>
function func(e){
.......
}
</script>

Line1<br>
<img id="toggleAll" name="toggleAll" src="images/expand_icon.gif"/>
<br>
<table></table>
<%
Dim aspx_e As String = ""
aspx_e=..... 'set this variable to something. I can't do this coding
up top
%>

'Now I will set the onclick, but it won't work
<script type="text/javascript" language="javascript">
$('toggleAll').onclick="func('<% Response.Write(aspx_e)%>')";
</script>

'This one works:
<img src="images/expand_icon.gif" onclick="'func('<
%Response.Write(aspx_e)%>')" />
 
C

CIndy Lee

CIndy Lee said the following on 8/8/2007 8:04 PM:
I want to change the on click value of an image.

document.images['imageName'].onclick= function(){ alert('new onclick')}




Basically the aspx sets the value of the onclick, after the spot
where I want my image. I need to either set the onlick after (Which
didn't work), or declare the image later and have the HTML put the
image somewhere. Maybe I can do that with divs? (I'm just editing
code. I don't want to change to much. I know i could redo it all
with .NET controlls)
<script>
function func(e){
......
}
</script>
Line1<br>
<img id="toggleAll" name="toggleAll" src="images/expand_icon.gif"/>
<br>
<table></table>
<%
Dim aspx_e As String = ""
aspx_e=..... 'set this variable to something. I can't do this coding
up top
%>

Don't post your server side code for a client side solution. Post the
resulting HTML code.
'Now I will set the onclick, but it won't work
<script type="text/javascript" language="javascript">
$('toggleAll').onclick="func('<% Response.Write(aspx_e)%>')";

$, is that prototype code?

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ -http://jibbering.com/faq/index.html
Javascript Best Practices -http://www.JavascriptToolbox.com/bestpractices/- Hide quoted text -

- Show quoted text -

$ is javascript telling it's an img id (I think). I just want to
change the toggleAll.onclick.
 
D

David Mark

CIndy Lee said the following on 8/8/2007 8:04 PM:
I want to change the on click value of an image.

document.images['imageName'].onclick= function(){ alert('new onclick')}




Basically the aspx sets the value of the onclick, after the spot
where I want my image. I need to either set the onlick after (Which
didn't work), or declare the image later and have the HTML put the
image somewhere. Maybe I can do that with divs? (I'm just editing
code. I don't want to change to much. I know i could redo it all
with .NET controlls)
<script>
function func(e){
......
}
</script>
Line1<br>
<img id="toggleAll" name="toggleAll" src="images/expand_icon.gif"/>
<br>
<table></table>
<%
Dim aspx_e As String = ""
aspx_e=..... 'set this variable to something. I can't do this coding
up top
%>

Don't post your server side code for a client side solution. Post the
resulting HTML code.
'Now I will set the onclick, but it won't work
<script type="text/javascript" language="javascript">
$('toggleAll').onclick="func('<% Response.Write(aspx_e)%>')";

$, is that prototype code?

Prototype or one of its derivatives. I think some .NET frameworks
include Prototype automatically, which is another reason to
avoid .NET.
 
D

David Mark

David Mark said the following on 8/8/2007 8:51 PM:



If .NET automatically included Prototype then it is just one more
example of the ineptitude of MS programmers

I am pretty sure Ajax.NET includes it. Somebody here reported seeing
a suspicious "prototype.js" in its distribution. I don't remember if
it was determined to be Prototype, but it wouldn't surprise me. MS
also uses and endorses BrowserHawk. (!)

and one more reason I won't
ever use .NET

I've never used it, but I have had to debug its output many times (it
is never pretty.)
 
F

Franjanko

I am pretty sure Ajax.NET includes it. Somebody here reported seeing
a suspicious "prototype.js" in its distribution. I don't remember if
it was determined to be Prototype, but it wouldn't surprise me. MS
also uses and endorses BrowserHawk. (!)

and one more reason I won't


I've never used it, but I have had to debug its output many times (it
is never pretty.)- Hide quoted text -

- Show quoted text -


I'm an asp.net programmer and the ASP.NET Ajax framework uses the
dollar $ caracter in front of other keywords like $get('id') is a
shortcut for document.getElementById('id').

The $ used alone doesn't do anything, and I also don't think asp.net
ajax includes the prototype library, definetly not.

I believe the onclick event is not getting added to the image just
because the $ doesn't do anything in this case, you should use
document.getElementById() or other standard dom methods.
 
D

David Mark

I'm an asp.net programmer and the ASP.NET Ajax framework uses the

You have my sympathies.
dollar $ caracter in front of other keywords like $get('id') is a
shortcut for document.getElementById('id').

The $ used alone doesn't do anything, and I also don't think asp.net
ajax includes the prototype library, definetly not.

You don't think it does or it definitely does not? Somebody recently
reported that they saw a prototype.js file in the distribution.
Perhaps they were mistaken or it was another prototype.js that MS
created.
I believe the onclick event is not getting added to the image just
because the $ doesn't do anything in this case, you should use
document.getElementById() or other standard dom methods.

Or if I understand your previous comment, $get? And in what case
would $ alone do anything unless Prototype (or the like) was part of
the page?
 
F

Franjanko

You don't think it does or it definitely does not? Somebody recently
reported that they saw a prototype.js file in the distribution.
Perhaps they were mistaken or it was another prototype.js that MS
created.

In the client side asp.net ajax library, there are no such
prototype.js files, this is sure, I've got it here in front of me.
Or if I understand your previous comment, $get?

if the asp.net client library is included in the page, then you can
use $get() instead of document.getElementById().

And in what case
would $ alone do anything unless Prototype (or the like) was part of
the page?- Hide quoted text -

I use heavily jquery side by side with asp.net ajax and I didn't have
to do any tricks to make them work toghether, in this case $ always
represent the jquery object.

I've tryied alert($) in a page with only ms ajax and it returned
undefined so the $ alone is free to be assigned to other libraries.

I hope this makes sense...

thanks for your sympathies :)
 

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. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,444
Messages
2,571,708
Members
48,796
Latest member
Greg L.
Top