473,883 Members | 1,692 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 1908
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
13097
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
9728
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
3011
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
3547
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
2559
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
31727
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
3096
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
9778
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
11112
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
10730
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...
0
10405
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9559
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5784
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5980
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4602
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
2
4205
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.