473,794 Members | 2,754 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problem with Setting the "src" of an "img" using javascript


Hello,

In my asp.net 2.0 page, I have a hyperlink with an arrow image

<a id="imgtest" href="#"onclick ="return hideColumn()">
<img id="imgArrow" src="App_Themes/Trmis/WebResource3.gi f"
alt="Click" />
</a>

WebResource3.gi f is an arrow pointing left and when I click on it I
want to replace it with WebResource4.gi f which is an arrow pointing
right, but for some reason the code below is not working.

<script language="javas cript" type="text/javascript" >
var testVar = 1;
var aDOM = 0, ieDOM = 0, nsDOM = 0; var stdDOM =
document.getEle mentById;
if (stdDOM) aDOM = 1; else {ieDOM = document.all; if (ieDOM) aDOM = 1;
else {
var nsDOM = ((navigator.app Name.indexOf('N etscape') != -1)
&& (parseInt(navig ator.appVersion ) ==4)); if (nsDOM) aDOM = 1;}}
function xDOM(objectId, wS) {
if (stdDOM) return wS ? document.getEle mentById(object Id).style:
document.getEle mentById(object Id);
if (ieDOM) return wS ? document.all[objectId].style:
document.all[objectId];
if (nsDOM) return document.layers[objectId];
}

function hideColumn()
{
var objs = xDOM('menu_colu mn',1)
var objs2 = xDOM('imgArrow' ,1)
if ( objs.display != 'none' )
{
objs.display = 'none';
objs2.src = 'App_Themes/Trmis/WebResource4.gi f'
}
else
{
objs.display = 'block';
objs2.src = 'App_Themes/Trmis/WebResource3.gi f'
}

return true;
}

</script>

Any help will be appreciated.

Thanks,

Burak

May 19 '06 #1
9 1901
what brower(s) are you testing with? Are you getting any specific
errors in the javascript console?

May 19 '06 #2

I am using IE 6.0 and I am not getting any errors in the browser.

what is the javascript console?

May 19 '06 #3
in firefox if you go to Tools | JavaScript console, you get some really
helpful javascript debugging info. much more specific than IE

May 19 '06 #4
replace all your script with this script and let me know if it works:
<script language="javas cript" type="text/javascript" >

function hideColumn()
{

var objs = document.getEle mentById('menu_ column').style;
var objs2 = document.getEle mentById('imgAr row');
if ( objs.display != 'none' )
{
objs.display = 'none';
objs2.src = 'App_Themes/Trmis/WebResource4.gi f'
}

else
{
objs.display = 'block';
objs2.src = 'App_Themes/Trmis/WebResource3.gi f'

}

return true;

}

</script>

May 19 '06 #5

Thanks Walton, it worked. :)

May 19 '06 #6
Walton said the following on 5/19/2006 10:32 AM:

Please quote what you are replying to.

If you want to post a followup via groups.google.c om, don't use the
"Reply" link at the bottom of the article. Click on "show options" at
the top of the article, then click on the "Reply" at the bottom of the
article headers.

<URL: http://www.safalra.com/special/googlegroupsreply/ >
replace all your script with this script and let me know if it works:


Looks like a lot of trouble to simply change the source of an image.

function swapPic(){
document.images['imagename'].src=document.i mages['imagename'].src.match('Web Resource4.gif') ?'WebResource3. gif':'WebResour ce4.gif';

}

It could be made generic very simply though.
--
Randy
comp.lang.javas cript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
May 19 '06 #7
Please quote what you are replying to.

If you want to post a followup via groups.google.c om, don't use the
"Reply" link at the bottom of the article. Click on "show options" at
the top of the article, then click on the "Reply" at the bottom of the
article headers.

<URL: http://www.safalra.com/special/googlegroupsreply/ >

Thanks for the head's up. I'm new to this kind of stuff.


Looks like a lot of trouble to simply change the source of an image.

If you look at the script again, you'll notice he's not just changing
the source of an image. he also wants to hide/unhide a column, which
may or may not be referenced easily relative to the image element. So
there is a bit more to it than your solution.

function swapPic(){
document.image s['imagename'].src=document.i mages['imagename'].src.match('We* bResource4.gif' )?'WebResource3 .gif':'WebResou rce4.gif';
}


I never knew about the document.images properties before... is it
compatible in most browsers?

May 19 '06 #8
Walton said the following on 5/19/2006 4:20 PM:

<snip>
Looks like a lot of trouble to simply change the source of an image.

If you look at the script again, you'll notice he's not just changing
the source of an image. he also wants to hide/unhide a column, which
may or may not be referenced easily relative to the image element. So
there is a bit more to it than your solution.


Then you add a second function that I have posted twice in the last week
or so:

function changeVisibilit y(elem,visibili tyMode){
document.getEle mentById(elem). style.visibilit y = visibilityMode;
}

And call it appropriately with the element ID and the visibility Mode
you want, whether visible or hidden.

But to be honest, I stopped reading his text (I don't want to call it
code or crap) when I read the part with navigator.appNa me as 99.99% of
code that is based on the navigator.appNa me needs to be re-written as it
is crap code.
function swapPic(){
document.images['imagename'].src=document.i mages['imagename'].src.match('We* bResource4.gif' )?'WebResource3 .gif':'WebResou rce4.gif';
}


I never knew about the document.images properties before... is it
compatible in most browsers?


NN4, IE4> Any Mozilla browser and a ton more. It is a lot more
compatible than gEBI is, that is for sure.

But, document.images is a collection, not a property.
--
Randy
comp.lang.javas cript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
May 19 '06 #9
Burak Gunay wrote:
In my asp.net 2.0 page, I have a hyperlink with an arrow image

<a id="imgtest" href="#"onclick ="return hideColumn()">
<img id="imgArrow" src="App_Themes/Trmis/WebResource3.gi f"
alt="Click" />
</a>
This is XHTML markup. XHTML UAs most certainly already support the
`onclick' attribute for `img' elements; you do not need a not gracefully
degrading a[href=#,onclick]:

<img src="App_Themes/Trmis/WebResource3.gi f" alt="Click"
id="imgArrow" onclick="return hideColumn();" />

See also <URL:http://jibbering.com/faq/>

Note however, that IE does not support XHTML. AFAIK, it is the major
drawback of ASP.NET that it generates XHTML markup code that is served
as text/html and therefore relies on error correction to be properly
displayed. That is Microsoft's idea of proper XHTML support ...

<URL:http://hixie.ch/advocacy/xhtml>
WebResource3.gi f is an arrow pointing left and when I click on it I
want to replace it with WebResource4.gi f which is an arrow pointing
right, but for some reason the code below is not working.


Well, the code is simply junk.

<URL:http://pointedears.de/scripts/test/whatami>
And prophylactic: <URL:http://validator.w3.or g/>
PointedEars
--
The English government is much of a German poodle as
other governments. The Germans infiltrated them all.
-- "The only real Barbara Schwarz", dsw.scientology ,
<16************ **************@ posting.google. com>)
May 24 '06 #10

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

Similar topics

14
13089
by: Gregory | last post by:
Hello, I'm trying to do the above in order to process an image and return the result to an html image control. It fails and my key suspects are either the variable that I'm passing in - ImageName - for processing, or the return data which is done (or not as the case may be) by imagejpeg($img) in the script, after header("Content-type: image/jpeg"). Any insights would be most welcome, especially debugging techniques and a pointer to...
12
9714
by: bhennon | last post by:
Hey all, I have a small php script that calls a random image at the following page. http://www.2006ymcanationals.com/random.php IT WORKS IF I go directly to the above link. I am trying to call that in another page so that i get a random image the page is http://2006ymcanationals.com/index.php using <img
8
3007
by: Eric Bragas | last post by:
What is this? <img src="{$ ImagesDir}/photo.gif"> I KNOW what an HTML image tag looks like. But what do you call that in the file source? Is it like a virtual directory in IIS? It's some type of variable obviously, but can somebody tell me what it's called so I can research how it works? thanks.
24
3532
by: Charles Crume | last post by:
Hello; My "index.htm" page has 3 frames (content, navigation bar, and logo). I set the "SRC" of the "logo" frame to a blank gif image and then want to change it's contents after the other two frames have been loaded by using a javascript statement from the "navigation" frame, as shown below: top.window.ccs_logo.src = 'images/ccs_logo.gif'; alert(top.window.ccs_logo.src);
22
2548
by: David. E. Goble | last post by:
Hi All; I have a few of these; sigsImages="sigs/finished1.jpg" sigsImages="sigs/foghorn.jpg" lower I have;
10
31706
by: FX | last post by:
I wanna publish a script on my site which allows me to hide image source. i have rough idea abt it. i`ll point src to some php page like: <img src="image.php"> & in tht php wat exactly shud be done so tht user doesnt come to know the real source location of image file upon clicking its properties. I've seen websites doing this. can somebody post the script for it? Thanx in advance
5
3088
by: enaz | last post by:
Ok, so, this is my first post, if there is any info i am leaving out please tell me this is the function: function mouseOver(c) { alert(c); <!-- just for debugging--> if (c.src == "red.jpg") {
0
9671
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9518
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10433
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10212
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10161
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7538
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5560
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4112
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2919
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.