473,809 Members | 2,703 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Switch/case how to use it correctly

I've been looking at implementing switch/case on my photo gallery.
Most of the sites I've seen so far, only show the bare basics.
With no real practical examples.
As brucie does with his butterlies and bugs, he uses switch/case, but in
php.

Visitor clicks on a thumbnail selection and the thumbs appear.
Selection of a thumb shows the larger pic AND description.

Since the selection is basically making a choice as within a form, how does
one go about applying what has been chosen, to appear in the proper place?
In the examples, they all favor using simple alert messages as examples.

What I need, is an example of how to manipulate the cases and direct the
coding to the proper areas.

If anyone has a site that would explain this better, please post it.

Jul 23 '05 #1
13 2020
On Sat, 29 Jan 2005 09:45:17 -0600, Richard <An*******@127. 001> wrote:
I've been looking at implementing switch/case on my photo gallery.


Why? Do you really want to write a case clause for every single image in
the gallery?

[snip]

Mike

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.
Jul 23 '05 #2
On Sat, 29 Jan 2005 16:27:54 GMT Michael Winter wrote:
On Sat, 29 Jan 2005 09:45:17 -0600, Richard <An*******@127. 001> wrote:
I've been looking at implementing switch/case on my photo gallery.

Why? Do you really want to write a case clause for every single image
in
the gallery? [snip]


Would it not be easier than writing a swap routine for each and every image?
As I see it, that's the purpose of switch/case.
A simpler way of writing if/then.
I would much rather write onclick="dothis ()" then
onclick="docume nt.image.src="b lah blah" for each and every item.
Jul 23 '05 #3
Richard wrote:
I've been looking at implementing switch/case on my photo gallery.
Most of the sites I've seen so far, only show the bare basics.
With no real practical examples.
As brucie does with his butterlies and bugs, he uses switch/case, but in
php.
The "switch/case" construct is the method of last resort, imho.
Mick

Visitor clicks on a thumbnail selection and the thumbs appear.
Selection of a thumb shows the larger pic AND description.

Since the selection is basically making a choice as within a form, how does
one go about applying what has been chosen, to appear in the proper place?
In the examples, they all favor using simple alert messages as examples.

What I need, is an example of how to manipulate the cases and direct the
coding to the proper areas.

If anyone has a site that would explain this better, please post it.

Jul 23 '05 #4
On Sat, 29 Jan 2005 10:48:08 -0600, Richard <An*******@127. 001> wrote:
On Sat, 29 Jan 2005 16:27:54 GMT Michael Winter wrote:
[snip]
Do you really want to write a case clause for every single image in the
gallery?

[snip]


Would it not be easier than writing a swap routine for each and every
image?


What on Earth gives you the impression that that's necessary? Good grief!
As I see it, that's the purpose of switch/case.
A simpler way of writing if/then.
The purpose of the switch statement is to compare many values to a single
expression. In general, if statements evaluate different expressions.
I would much rather write onclick="dothis ()" then
onclick="docume nt.image.src="b lah blah" for each and every item.


Both are excessive.

Mike

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.
Jul 23 '05 #5
Richard wrote:
On Sat, 29 Jan 2005 16:27:54 GMT Michael Winter wrote:

On Sat, 29 Jan 2005 09:45:17 -0600, Richard <An*******@127. 001> wrote:
I've been looking at implementing switch/case on my photo gallery.


Why? Do you really want to write a case clause for every single image
in
the gallery?


[snip]

Would it not be easier than writing a swap routine for each and every image?


No. The easiest way would be a function that accepts generic parameters
and acts upon those parameters. Of course, to write such a function
requires at least a minimum understanding of scripting.
As I see it, that's the purpose of switch/case.
No, the above mentioned use is not the purpose of switch/case
A simpler way of writing if/then.
Yes.
I would much rather write onclick="dothis ()" then
onclick="docume nt.image.src="b lah blah" for each and every item.


onclick="doThis ('imageName','d iv Text');return false"

--
Randy
comp.lang.javas cript FAQ - http://jibbering.com/faq
Jul 23 '05 #6
On Sat, 29 Jan 2005 18:09:53 GMT Mick White wrote:
Richard wrote:
I've been looking at implementing switch/case on my photo gallery.
Most of the sites I've seen so far, only show the bare basics.
With no real practical examples.
As brucie does with his butterlies and bugs, he uses switch/case, but
in
php.

The "switch/case" construct is the method of last resort, imho.
Mick


I feel that in my situation, I may have to.
It beats writing out a long string of "if" statements.
Which it is actually designed for as an alternative to "if".
Besides, I can follow the "case" elements easier.
Jul 23 '05 #7
"Richard" <An*******@127. 001> wrote in message
news:ct******** *@news2.newsguy .com...
On Sat, 29 Jan 2005 18:09:53 GMT Mick White wrote:
Richard wrote:

I've been looking at implementing switch/case on my photo gallery.
Most of the sites I've seen so far, only show the bare basics.
With no real practical examples.
As brucie does with his butterlies and bugs, he uses switch/case, but
in
php.

The "switch/case" construct is the method of last resort, imho.
Mick


I feel that in my situation, I may have to.
It beats writing out a long string of "if" statements.
Which it is actually designed for as an alternative to "if".
Besides, I can follow the "case" elements easier.


Tell us what you're working with so we can be of more help.

Do you have a list of URLs for the thumbnail images and corresponding URLs
for the enlarged versions plus a description of each?

For example,

http://www.google.com/images/google_sm.gif
http://www.google.com/images/logo.gif
Google.Logo
Jul 23 '05 #8
On Sat, 29 Jan 2005 13:13:25 -0600 McKirahan wrote:
"Richard" <An*******@127. 001> wrote in message
news:ct******** *@news2.newsguy .com...
On Sat, 29 Jan 2005 18:09:53 GMT Mick White wrote:
> Richard wrote: >> I've been looking at implementing switch/case on my photo gallery.
>> Most of the sites I've seen so far, only show the bare basics.
>> With no real practical examples.
>> As brucie does with his butterlies and bugs, he uses switch/case, but
>> in
>> php.

> The "switch/case" construct is the method of last resort, imho.
> Mick
I feel that in my situation, I may have to.
It beats writing out a long string of "if" statements.
Which it is actually designed for as an alternative to "if".
Besides, I can follow the "case" elements easier.


Tell us what you're working with so we can be of more help. Do you have a list of URLs for the thumbnail images and corresponding
URLs
for the enlarged versions plus a description of each? For example, http://www.google.com/images/google_sm.gif
http://www.google.com/images/logo.gif
Google.Logo

www.somestuff.batcave.net/menu1.html


Jul 23 '05 #9
In article <ct*********@ne ws2.newsguy.com >,
"Richard" <An*******@127. 001> wrote:

www.somestuff.batcave.net/menu1.html
Here is a possibility.

The code may be a little hard to follow because it uses document.write
to generate the html. I did this because I got tired of typing out all
the long web addresses. To see the generated html, look for the term
one liner in this forum. The one line javascript program will show you
the generated html.

Some of the url's are long. Hope they come out.

Robert

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Swap images</title>
<style type="text/css">

#footer{
clear: both;
padding-left: 20px;
padding-right: 20px;
padding-top: 5px;
padding-bottom: 5px;
background: #eee;
}

..hide { display: none }

</style>

<script type="text/javascript">
var nasaPath = "http://spaceplace.nasa .gov" +
"/en/educators/images/solarsystem/";

var imageCount = 0;

/* I am using NASA images.
The thumbs have the suffix _T
The full size image has the suffix _L

I pass the image name without the path and the suffix.

To indicate the first call, I pass three arguements. In
the first call, I do not generate the tr tags.

*/

function genImage(link,r ollover,msg)
{
// The first row has the full size image, so the
// tr tag is coded below.

// For the second image and all further images, code
// the tr tags.
if (arguments.leng th == 3)
{ document.writel n("<tr>");}

var data = "<td width='110' valign='top'>" +
"<a href='" + nasaPath + link + "_L.jpg'>\n " +
"<img id='image" + imageCount + "'" +
"src='" + nasaPath + link + "_T.jpg'\n" +
"onclick='retur n changeImg(\"" +
nasaPath + link + "_L.jpg\",\ "" + msg + "\");'\n" +
"onmouseover='s etThumb(\"image " + imageCount +
"\",\"" + nasaPath + rollover + "_T.jpg\")' \n" +
"onmouseout='se tThumb(\"image" + imageCount +
"\",\"" + nasaPath + link + "_T.jpg\")' \n" +
">\n" +
"<\/a></td>";
imageCount++
document.writel n(data);

// End tr tag
if (arguments.leng ht == 3)
{ document.writel n("<\/tr>");}

}

function changeImg(name, msg)
{

document.images["big_image"].src =

"http://spaceplace.jpl. nasa.gov/en/_images/common/nasa_header/logo_nasa.g
if";
document.images["big_image"].src = name;
changeText('tex t',msg);
return false;
}

function setThumb(id,nam e)
{
document.images[id].src = name;
}

function changeText(labe l,text)
{

var node;
if (document.getEl ementById)
{
var node = document.getEle mentById(label) ;
if (node)
{

node.innerHTML = text;
return; /*See if we already inserted a node. */

}
else
{
alert("You need to create a span tag with " +

"the id of " + label + ".");
return;
}
}
else
{
alert(" document.getEle mentByID failed. " +
"You need to use a newer browser.");
return;
}

}

</script>
</head>
<body>
<h1 style="text-align: center;">Solar System</h1>
<table>
<tr>
<script type="text/javascript">
genImage("Mercu ryglobe1","Merc uryglobe2","Pla net Mercury","first ");

</script> <td width="600" height="800" align="center" valign="top"
rowspan="7">
<img id="big_image"
src="
http://spaceplace.jpl.nasa.gov/en/_i...r/logo_nasa.gi
f"

<br><span id='text'>Repla cement text here...</span>
</td>
</tr>

<script type="text/javascript">
genImage("Venus ","venusglobe", "Planet Venus");
genImage("clem_ full_moon","Ear th_moon","Earth 's moon");
</script> </table>
<div id="footer">
<p>These image are from NASA. See:<br>
http://spaceplace.jpl.nasa.gov/en/ed...s_images.shtml
</p>
</div>

<script type="text/javascript">
// Preload the rollover images.
var selimage = new Image();
selimage.src = nasaPath + "Mercuryglobe2_ T.jpg";
var selimage = new Image();
selimage.src = nasaPath + "venusglobe_T.j pg";
var selimage = new Image();
selimage.src = nasaPath + "Earth_moon_T.j pg";
var selimage = new Image();
selimage.src = nasaPath + "marsglobe3_T.j pg";

</script>

</body>
</html>
Jul 23 '05 #10

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

Similar topics

4
1383
by: Robert Scheer | last post by:
Hi. I am trying to use switch this way, without success: //thedata is a numeric variable switch (thedata) { case < 10: ... case < 20: ...
6
1512
by: Sridhar_Gadda | last post by:
Hello friends, I am new to C and I have written a code but #include <stdio.h> main() { init_funtion(); }
65
6705
by: He Shiming | last post by:
Hi, I just wrote a function that has over 200 "cases" wrapped in a "switch" statement. I'm wondering if there are performance issues in such implementation. Do I need to optimize it some way? In terms of generated machine code, how does hundreds of cases in a switch differ from hundreds of if-elses? Do compilers or processors do any optimization on such structured code? Do I need to worry about the performance, usually?
9
8854
by: Eric S. | last post by:
Why doesn't something like this work? I get "a constant value is expected" on all 3 case statements. private DataGrid CurrentDataGrid(DataGrid firstDg, DataGrid secondDg) { try { switch (true) { case firstDg.Items.Count != 0 & secondDg.Items.Count != 0:
9
1734
by: PhreakRox | last post by:
The ToClose switch in this program is not working as expected, it allways returns a null value, if anyone knows a way to fix up the code, or can suggest a better method of doing so, your help would be greatly appreciated using System; using System.Collections.Generic; using System.Text; using System.Drawing;
0
1372
by: Sudz28 | last post by:
Greetings! I am attempting to write a program that will allow a user to manipulate data read from a file, and am obviously in no way near finished. However, one problem I'm having that I don't understand is with my switch subroutine. In the below code, if I select "d" or anything that is an invalid response, it loops correctly back to the menu. However, if I attempt to insert (i), find (f), or delete (d) it loops back to the menu *but*...
9
1902
by: yndygo | last post by:
Alright then - I know it's got to be out there somewhere, but I can't find it... I'm looking at a piece of code and there's some debate as to what the behavior will be. Given a switch/case where there is a function call after the switch but *before* the first case statement, will the function call never get reached? or always?
10
2441
by: anon.asdf | last post by:
Here's a reminder of duff's device: /*************************************/ #include <stdio.h> #define STEP 8 #define MAX_LEN STEP*4+1 #define SOURCE_LEN 28
13
11864
by: Satya | last post by:
Hi everyone, This is the first time iam posting excuse me if iam making any mistake. My question is iam using a switch case statement in which i have around 100 case statements to compare. so just curious to find out is it effective to use this method?? or is there is any other alternative method present so that execution time and code size can be reduced?? Thanks in advance.
0
9721
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
9601
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
10637
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...
1
10379
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
10115
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...
1
7660
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
5687
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4332
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
3014
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.