Closed Thread Icon

Topic awaiting preservation: Using Shorthand Conditional Pages that link to <a href="https://ozoneasylum.com/backlink?for=8663" title="Pages that link to Topic awaiting preservation: Using Shorthand Conditional" rel="nofollow" >Topic awaiting preservation: Using Shorthand Conditional\

 
Author Thread
Hiroki
Paranoid (IV) Inmate

From: NZ
Insane since: Dec 2002

posted posted 05-21-2003 05:03

Hi, guys. I am trying to understand Using Shorthand conditional!

What I am trying to do is that two different pictured pops up accoring to the result of confirm box.

My code is:

[code]<html>
<head>
</head>
<body>
<img src="&{(confirm('Would you pefer 1 to 2 ?')) ? '1.gif' : '2.gif'};">

</body>
</html>

If user clicks yes, 1.gif popus up. Ortherwise 2.gif will be shown.

But....IE does not show anything....
Would you see why????
Please help.
many thanks.

Hiroki Kozai

bitdamaged
Maniac (V) Mad Scientist

From: 100101010011 <-- right about here
Insane since: Mar 2000

posted posted 05-21-2003 05:27

Well I've never seen the &{ ... } bit so I don't know what that is but usually you need to return something for that to work.



.:[ Never resist a perfect moment ]:.

Hiroki
Paranoid (IV) Inmate

From: NZ
Insane since: Dec 2002

posted posted 05-21-2003 06:07

Hi, bitdamaged.
many many thanks for your reply.
Well, my book is pretty old. I found this in public library.
At that time, this book was written for IE3.
Hmm.....It is stone age, isn't it???
Does anybody know???

Hiroki Kozai

poi
Paranoid (IV) Inmate

From: France
Insane since: Jun 2002

posted posted 05-21-2003 12:01

Like Bitdamaged, I've never seen the &{foo} syntax. I've searched in the Javascript 1.3 Client References ( Javascript 1.3 was introduced in Navigator 4.06, so it covers the features of 3rd generation browsers ), and there's no sign of the &{foo} thingy.

It might be proprietary to IE3, and I guess it's deprecated now.

On the other hand, I'm surprised by the lack of javascript: protocol in your syntax. If you wish to run/return some javascript in the src, you should do

<img src="javascript:foo" >

Where foo, is usually ( at least that's the only way I've seen it used ) a JavaScript variable containing an XBM image.

All the more, the script below, shows that the this keyword, used in the src attribute refers to SELF.

code:
<html>
<script language="javascript">
function intro( obj )
{
bla = "OBJ "+ ((obj==self)?"==":"!=") +" SELF"
bla +="\n\n"
for( i in obj )
bla+= "\n\t"+ i +"\t\t"+ obj
alert( bla)
}

</script>
<body>
<img name="grugru" src="javascript:intro(this)" >
</body>
</html>

Thus, the only way to do what you want, is to send the name/id of the image you wanna change to a function and then update the src attribute.

Hope that helps.

Mathieu "POÏ" HENRI

[This message has been edited by poi (edited 05-21-2003).]

lallous
Paranoid (IV) Inmate

From: Lebanon
Insane since: May 2001

posted posted 05-21-2003 13:46

Hello,

I have read about the &{foo} syntax time ago and I remember well that I doesn't work with all browesers.



Elias,

RoyW
Bipolar (III) Inmate

From:
Insane since: Aug 2001

posted posted 05-21-2003 22:22

How to use "Shorthand Conditional"

Also known as a "ternary operator" (and sometimes "binary operator")

syntax
expr ? true_expr : false_expr ;

expr: a valid javascript expression that returns true or false
true_expr: a valid javascript expression executed if "expr" is true (can return a value)
false_expr: a valid javascript expression executed if "expr" is false (can return a value)

e.g.

str = x>10 ? "X is greater than ten" : "X is less than ten" ;

str = "X is " + (x>10 ? "greater" : "less") + " than ten";

and a much abused way of doing it

x > 10 ? str = "X is greater than ten" : str = "X is less than 10" ;

----------------------
JavaScript Entities, only valid in NS4.
<tag attr = "&{js code};" /tag>

e.g.
<script>
theImg = "a.gif";
</script>

<img src = "&{theImg};">

the code you posted should work in NS4.
----------------------------

Cross browser solution
<body>

<script>
document.write('<img src="' + (confirm("Would you prefer 1 to 2?") ? "1.gif" : "2.gif") + '">');
</script>

</body>

poi
Paranoid (IV) Inmate

From: France
Insane since: Jun 2002

posted posted 05-22-2003 00:29

RoyW: LOL, your solution is quite easy. I always forget the document.write function mainly 'coz I consider it as a "Middle Age" tool in those times of DOM, and also 'coz I've had some really bad suprises with it in NN4 ( e.g. the code generated in a document.write overwrote the code being in the current tag and its siblings. Crazy. )

Mathieu "POÏ" HENRI

RoyW
Bipolar (III) Inmate

From:
Insane since: Aug 2001

posted posted 05-22-2003 06:37

hi poi,
Yep, document.write can have some really wierd side effects, especially in NS4.
I know of one situation (but cannot quite remember it now) where document.write
in NS4 would produce the output twice but with an extra "t" in one of the tags.
I am sure is was a doc.write within a <td> tag.
I try to avoid doc.write... but it can have its uses.

I was very interested in your post. Very complex.
What is an XBM image? can you create an image in JavaScript? Wouldn't your intro() func have to return some sort of byte array or something?

poi
Paranoid (IV) Inmate

From: France
Insane since: Jun 2002

posted posted 05-22-2003 10:39

RoyW: The weird behavior of document.write I mentionned made me add many lines of HTML comments to make sure the document.write wouldn't crush some useful tags.

Regarding, my post, it's not that complex The intro() function is just here to do some introspection on the this object given in the src of the IMG tag. I did that to see what it refered to, if it was refering to the IMG itself it would have bring an elegant solution. But due to the javascript: protocol I was almost sure it would refer to document or self.

The XBM format, looks like some C code. And describes the width, height and raw datas of a B&W image. Notice that IE uses the white in XBM images as a chroma color. This format is quite interresting because of its simplicity. It's just a string and thus it can be generated and contained in JavaScript.


For more informations about the construction or the use of XBM images, check:
http://www.dcs.ed.ac.uk/home/mxr/gfx/2d/XBM.txt
http://www.mit.edu/afs/sipb.mit.edu/project/doc/ibitmap/ibitmap.html
http://wings.buffalo.edu/images/xbms.html

and obviously

Lee SEMEL's WOLFENSTEIN 5K entry for the5K 2002
My very first test of B&W raycasting in early 2001

Cheers,

Mathieu "POÏ" HENRI

RoyW
Bipolar (III) Inmate

From:
Insane since: Aug 2001

posted posted 05-23-2003 20:13

Hi poi,
Thanks for the links. That 3d maze is 'amazing'

Cheers
Roy.

« BackwardsOnwards »

Show Forum Drop Down Menu