473,608 Members | 1,809 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

I don't get what's wrong here...

I have an html img with a source of 'lbug.gif'. I want to be able to change
out the source of the img by clicking a button. Here's my code:

function swapPic()
{
if (document.Form1 .imgBug.src = "lbug.gif")
{
document.Form1. imgBug.src = "stopbug.jp g";
}
else if (document.Form1 .imgBug.src = "stopbug.jp g")
{
document.Form1. imgBug.src = "lbug.gif"
}
}

When I click the button the 1st time, the code executes as expected. Each
successive
time I click the button, the same code executes which is the:

if (document.Form1 .imgBug.src = "lbug.gif")
{
document.Form1. imgBug.src = "stopbug.jp g";
}

And the source never switches back to 'lbug.gif'
What concept am I missing here?

TIA,
Marc Miller
'Confused in Northeast Penna.'

Apr 24 '06 #1
9 1304
Marc Miller wrote:
When I click the button the 1st time, the code executes as expected. Each
successive time I click the button, the same code executes which is the:

if (document.Form1 .imgBug.src = "lbug.gif")
{
document.Form1. imgBug.src = "stopbug.jp g";
}

And the source never switches back to 'lbug.gif'
What concept am I missing here?


The difference between an assignment "=" and a comparison "==",
and a reasonable Subject header.

<URL:http://jibbering.com/faq/>
PointedEars
--
This above all: To thine own self be true.
-- William Shakespeare (1564-1616)
Apr 24 '06 #2

"Thomas 'PointedEars' Lahn" <Po*********@we b.de> wrote in message
news:61******** ********@Pointe dEars.de...
Marc Miller wrote:
When I click the button the 1st time, the code executes as expected.
Each
successive time I click the button, the same code executes which is the:

if (document.Form1 .imgBug.src = "lbug.gif")
{
document.Form1. imgBug.src = "stopbug.jp g";
}

And the source never switches back to 'lbug.gif'
What concept am I missing here?
The difference between an assignment "=" and a comparison "==",
and a reasonable Subject header.

<URL:http://jibbering.com/faq/>
PointedEars


--
This above all: To thine own self be true.
-- William Shakespeare (1564-1616)

Thomas,

Thanks for your response and you're right, a reasonable subject header is
much more appropriate.

Interestingly enough, I used the comparasion "==" in my first attempt ( in
the 'if' and 'else if' lines) and nothing happened.

I then changed it to the assignment "=" and, voila, the 'if' line works all
the time, except that it does not
correctly identify the 'src' attribute of the image.

I tried using 'switch' but that seems not to be an option at all.

By the way, my platform it asp.net 2003, .NET framework 1.1.

Thank again,
Marc Miller

Apr 24 '06 #3
Marc Miller wrote:
"Thomas 'PointedEars' Lahn" <Po*********@we b.de> wrote in message
news:61******** ********@Pointe dEars.de...
Marc Miller wrote:
When I click the button the 1st time, the code executes as expected.
Each
successive time I click the button, the same code executes which is the:

if (document.Form1 .imgBug.src = "lbug.gif")
{
document.Form1. imgBug.src = "stopbug.jp g";
}

And the source never switches back to 'lbug.gif'
What concept am I missing here?


The difference between an assignment "=" and a comparison "==",
and a reasonable Subject header.

<URL:http://jibbering.com/faq/>
PointedEars


--
This above all: To thine own self be true.
-- William Shakespeare (1564-1616)

Thomas,

Thanks for your response and you're right, a reasonable subject header is
much more appropriate.

Interestingly enough, I used the comparasion "==" in my first attempt ( in
the 'if' and 'else if' lines) and nothing happened.

I then changed it to the assignment "=" and, voila, the 'if' line works all
the time, except that it does not
correctly identify the 'src' attribute of the image.

I tried using 'switch' but that seems not to be an option at all.

By the way, my platform it asp.net 2003, .NET framework 1.1.

Thank again,
Marc Miller


Use the "==" operator, then send an alert if it is not true so you can
see what the value is. It may be adding
"http://www.yourdomain. com/your/path/to/image" to the string as it
loads the image. Thus you would need:

if (document.Form1 .imgBug.src ==
"http://www.yourdomain. com/your/path/to/image/lbug.gif") {
document.Form1. imgBug.src =
"http://www.yourdomain. com/your/path/to/image/stopbug.jpg";
}

- JS
http://www.endeavorpub.com

Apr 24 '06 #4
Marc Miller said the following on 4/24/2006 1:41 PM:
I have an html img with a source of 'lbug.gif'. I want to be able to change
out the source of the img by clicking a button. Here's my code:

function swapPic()
{
if (document.Form1 .imgBug.src = "lbug.gif")


Is imgBug the ID/NAME of your img element or is the name of an input
element in your form named Form1?

Second: Your if test is not testing for equality, it is testing to see
if it can set the .src property. It can so it passes the if test.

Third: Access images through the images collection.

Fourth: The .src of an img tag is not the filename. It is the fully
qualified path to the image file.

function swapPic(){
if (document.image s['imageNAME'].src.indexOf('l bug.gif') != -1)
{
document.images['imageNAME'].src = 'stopbug.gif';
}
else
{
document.images['imageNAME'].src = 'lbug.gif'
}
}

But even simpler:

function swapPic(){
document.images['imagename'].src=document.i mages['imagename'].src.match('lbu g.gif')?'stopbu g.gif':'lbug.gi f';
}

--
Randy
comp.lang.javas cript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Apr 24 '06 #5

"jshanman" <un**********@s bcglobal.net> wrote in message
news:11******** *************@v 46g2000cwv.goog legroups.com...
Marc Miller wrote:
"Thomas 'PointedEars' Lahn" <Po*********@we b.de> wrote in message
news:61******** ********@Pointe dEars.de...
> Marc Miller wrote:
>
>> When I click the button the 1st time, the code executes as expected.
>> Each
>> successive time I click the button, the same code executes which is
>> the:
>>
>> if (document.Form1 .imgBug.src = "lbug.gif")
>> {
>> document.Form1. imgBug.src = "stopbug.jp g";
>> }
>>
>> And the source never switches back to 'lbug.gif'
>>
>>
>> What concept am I missing here?
>
> The difference between an assignment "=" and a comparison "==",
> and a reasonable Subject header.
>
> <URL:http://jibbering.com/faq/>
>
>
> PointedEars


> --
> This above all: To thine own self be true.
> -- William Shakespeare (1564-1616)

Thomas,

Thanks for your response and you're right, a reasonable subject header is
much more appropriate.

Interestingly enough, I used the comparasion "==" in my first attempt (
in
the 'if' and 'else if' lines) and nothing happened.

I then changed it to the assignment "=" and, voila, the 'if' line works
all
the time, except that it does not
correctly identify the 'src' attribute of the image.

I tried using 'switch' but that seems not to be an option at all.

By the way, my platform it asp.net 2003, .NET framework 1.1.

Thank again,
Marc Miller


Use the "==" operator, then send an alert if it is not true so you can
see what the value is. It may be adding
"http://www.yourdomain. com/your/path/to/image" to the string as it
loads the image. Thus you would need:

if (document.Form1 .imgBug.src ==
"http://www.yourdomain. com/your/path/to/image/lbug.gif") {
document.Form1. imgBug.src =
"http://www.yourdomain. com/your/path/to/image/stopbug.jpg";
}

- JS
http://www.endeavorpub.com

JS,

That does work, and with the '==' operator and the fully qualified path. I
was
trying to avoid having to change the domain in the path however, to save the
necessity of changing the string every time there is a version
change/testing/and move
to production.

Thanks to all!

Marc Miller
Apr 24 '06 #6
jshanman said the following on 4/24/2006 2:36 PM:

<snip>

Use the "==" operator, then send an alert if it is not true so you can
see what the value is. It may be adding
"http://www.yourdomain. com/your/path/to/image" to the string as it
loads the image. Thus you would need:
It does. The .src property of an img object is always a fully qualified
path when your read its .src property.
if (document.Form1 .imgBug.src ==
"http://www.yourdomain. com/your/path/to/image/lbug.gif") {
document.Form1. imgBug.src =
"http://www.yourdomain. com/your/path/to/image/stopbug.jpg";
}


You don't have to include the fully qualified path when setting the
..src, the browser will do it for you. But, see my other reply :)

--
Randy
comp.lang.javas cript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Apr 24 '06 #7
Marc Miller said the following on 4/24/2006 2:45 PM:

<snip>
That does work, and with the '==' operator and the fully qualified path. I
was trying to avoid having to change the domain in the path however, to save
the necessity of changing the string every time there is a version
change/testing/and move to production.


You don't have to change it everytime if you dont worry with the domain
aspect. See my other reply:

function swapPic(){
document.images['imagename'].src=document.i mages['imagename'].src.match('lbu g.gif')?'stopbu g.gif':'lbug.gi f';
}

--
Randy
comp.lang.javas cript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Apr 24 '06 #8
Thanks Randy! Now that's elegant and I've already
put it in my 'code cupboard' for future use as well.

Also thanks again to Mr. PointedEars and jshanman.

Marc Miller
a.k.a. 'Shaky Slidewell'
(ps- don't ask 8-))
Apr 24 '06 #9
JRS: In article <61************ ****@PointedEar s.de>, dated Mon, 24 Apr
2006 20:06:23 remote, seen in news:comp.lang. javascript, Thomas
'PointedEars' Lahn <Po*********@we b.de> posted :


PointedEars
--
This above all: To thine own self be true.
-- William Shakespeare (1564-1616)

In your case, that's bad advice.

The material after your "-- " line does not comply with FYI28/RFC1855.
Please rectify your habits.

--
© John Stockton, Surrey, UK. yyww merlyn demon co uk Turnpike v4.00 MIME ©
Web <URL:http://www.uwasa.fi/~ts/http/tsfaq.html> -> Timo Salmi: Usenet Q&A.
Web <URL:http://www.merlyn.demo n.co.uk/news-use.htm> : about usage of News.
No Encoding. Quotes before replies. Snip well. Write clearly. Don't Mail News.
Apr 25 '06 #10

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

Similar topics

303
17562
by: mike420 | last post by:
In the context of LATEX, some Pythonista asked what the big successes of Lisp were. I think there were at least three *big* successes. a. orbitz.com web site uses Lisp for algorithms, etc. b. Yahoo store was originally written in Lisp. c. Emacs The issues with these will probably come up, so I might as well mention them myself (which will also make this a more balanced
0
2289
by: DP | last post by:
(2nd post, I think my first may have been to the wrong group - sorry) Hello Perl-ers - I´m hoping I can get some help here, because I'm very lost. Don't know Perl, I'm not a programmer. And this is something that has worked for me earlier, only now it doesn't anymore. --------------------------------- The ¨problem¨ script -
2
6118
by: Robert Oschler | last post by:
If I set window.onerror to an error handler I've created, I don't see the browser error dialogs anymore but I don't see the alert() messages in my error handler pop up either. Can someone tell me what I am doing wrong? Here's the test doc I'm using: =========== BEGIN TEST DOC =================== <HTML> <TITLE> OnError Test </TITLE> <HEAD>
23
2514
by: Carter Smith | last post by:
http://www.icarusindie.com/Literature/ebooks/ Rather than advocating wasting money on expensive books for beginners, here's my collection of ebooks that have been made freely available on-line by their authors. There are lots of them out there but this selection cuts out the junk. If you know of any other good books that are freely available please post a link to them here and I'll consider adding them to the site.
5
2824
by: titan0111 | last post by:
#include<iostream> #include<iomanip> #include<cstring> #include<fstream> using namespace std; class snowfall { private: int ft;
0
17767
by: Nashat Wanly | last post by:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnaskdr/html/askgui06032003.asp Don't Lock Type Objects! Why Lock(typeof(ClassName)) or SyncLock GetType(ClassName) Is Bad Rico Mariani, performance architect for the Microsoft® .NET runtime and longtime Microsoft developer, mentioned to Dr. GUI in an e-mail conversation recently that a fairly common practice (and one that's, unfortunately, described in some of our...
0
3002
by: U S Contractors Offering Service A Non-profit | last post by:
" Visionary Dreams " " Leaving New york City leaving to go " GOD noes were i Don't "
17
2517
by: =?Utf-8?B?Y2F0aGFyaW51cyB2YW4gZGVyIHdlcmY=?= | last post by:
Hello, I have build a website with approximately 30 html-pages. When I search this website in Google, I see the index.html or home.html on this website, but also other html-pages on this website. When I click in Google on one of these pages (not index.html or home.html), I am only linked to that one html-page and not to the website itself. Does anyone know how to fix this. Is there for example a metatag? Thanks
10
1716
by: Richard Maher | last post by:
Hi, Sorry if this is one of those issues that people feel passionate about and I assure you I'm not trolling but rather seeking guidance on which way to go with the web browser presentation of tabular result sets. I'm a newbie and don't know any better, but I immediately opted for Select Lists 'cos A) someone showed me :-) and b) 'cos I didn't think you could select from a Table without a Button-cell on each row (but a recent post of...
31
1901
by: Jo | last post by:
class A { public: char text_a; A() { *text_a=0; } ~A() {} }; //-----------------------------------------------------------------------------
0
8503
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
8488
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
8160
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,...
0
6826
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...
1
6017
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
3972
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
4036
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2479
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
0
1339
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.