/    Sign up×
Community /Pin to ProfileBookmark

Help correct this Script

Hi all, I am from Portugal ( Europe )and this is my first time here and I need some help.

I am working on a program and need a script similar to this one:
The program at the end of the scripting converts java into html for browser viewing.

[COLOR=red]
<table>
<tr>
<td>
<script type=”text/javascript” language=”JavaScript”>
if (“{@Foto1@}” != “#”) {
document.write(“<td><img src=”{@Foto1@}.JPG”></td>”);
}
else {
document.write(“<td></td>”);
}
</script>
</td>
<td>
<script type=”text/javascript” language=”JavaScript”>
if (“{@Foto2@}” != “#”) {
document.write(“<td><img src=”{@Foto2@}.JPG”></td>”);
}
else {
document.write(“<td></td>”);
}
</script>
</td>
</tr>
</table>
[/COLOR]

Now, the first part of the script works perfectly, being:

[COLOR=darkblue]<script type=”text/javascript” language=”JavaScript”>
if (“{@Foto1@}” != “#”) {
document.write(“<td><img src=”{@Foto1@}.JPG”></td>”);
}[/COLOR]

The same can not be said for the second part:

[COLOR=chocolate]else {
document.write(“<td></td>”);
}[/COLOR]

This being: If I write a NUMBER in the program where{@FOTO1@} applies, the program converts it to <td><img src=”1.JPG”></td>

If I leave it blank or write any thing else, instead of giving me <td></td> i get an icon with a red cross in the browser stating a bad link to the image.

Is there anyone there that can see where I went wrong?

Please, I have been at this war for a week.

to post a comment
JavaScript

16 Comments(s)

Copy linkTweet thisAlerts:
@NedalsSep 11.2004 — if ("{@Foto2@}" != "#") {

document.write("<td><img src="{@Foto2@}.JPG"></td>");

}

else {

document.write("<td></td>");

}

This will return "<td></td>" if, AND ONLY IF, {@Foto2@} = '#'
Copy linkTweet thisAlerts:
@PanteraauthorSep 11.2004 — Using:

if ("{@Foto2@}" != "#") {

document.write("<td><img src="{@Foto2@}.JPG"></td>");

}

else {

document.write("<td></td>");

}

When I write a NUMBER (ex: 5) in {@Foto2@} it does convert to:

<td><img src="5.JPG"></td>

and the rest of the script is ignored in the browser.

When I DONT write anything, then the browser does not read

<td></td>

Hope you understood my explanation.?
Copy linkTweet thisAlerts:
@steelersfan88Sep 11.2004 — What do you change the number sign to? If the delete the number sign, making the two values equal, you'll get what you need.
Copy linkTweet thisAlerts:
@PanteraauthorSep 11.2004 — Ok, the only way you will see what the problem is will be by testing the program I am working on.

Please download it to a file on your desktop or wherever you want and put in that same folder 2 numbered pictures. Open the software and where it asks for the number of the foto, put it in. The second one is optional, at the endo of the 2 questions there is a " save as html ", save it and then open the html file. You will see the problem.

Then open the browser coding and you will see what the browser is reading.

PLEASEEEEEEEEEEEE, I cant finish the program for this reason.

I have a small part of the software here:

http://www.realestatealgarve.com/GestaoInterna/Test1.exe
Copy linkTweet thisAlerts:
@steelersfan88Sep 12.2004 — If you post the code exactly that you are using, we won't need to download. Plus, it isn't safe downloading EXE files anyway. At least if they were compressed itno a ZIP file ...
Copy linkTweet thisAlerts:
@PanteraauthorSep 12.2004 — ? I did not compress because I have nothing to hide.

You can scan the file and even my site if you want to, i do need help and am not here to waste anybodys time.

My site is http://www.realestatealgarve.com and you can e-mail me, my addy is in the site as the creator.

Please, take a look, I am using the code exactly like it is here, but when the program converts, thats where something goes wrong with the code.

Thats the reason I put the .exe file on my server right now, it was to get serious help and not play the fool.

?
Copy linkTweet thisAlerts:
@NedalsSep 12.2004 — When I DONT write anything, then the browser does not read <td></td>[/quote]It won't; please read my earlier post.

If {@Foto2@} = '', you will get '<td><img src=""></td>'

ONLY if {@Foto2@} = "#", will you get "<td></td>" (that's the # symbol)

If that's not what you want you need to rewrite the if..else

For example, if you only want an image when {@Foto2@} is numeric

var num = "{@Foto2@}"; // whatever this is!

if (/^d+$/.test(num)) {

document.write("<td><img src="{@Foto2@}.JPG"></td>");

}

else {

document.write("<td></td>");

}
Copy linkTweet thisAlerts:
@PanteraauthorSep 12.2004 — Ok, what I need is the following:

The person must put in a NUMBER which coresponds to the number of the foto that he/she wants displayed in the browser.

if ("{@WhatNumber@}" != "#") {

document.write("<td><img src="{@WhatNumber@}.JPG"></td>");

}

The above script works perfectly, the person writes in a number and the browser shows the foto. If they dont write in a number, the browser shows a bad link icon, this icon is what i am trying to get rid of by geting the browser to read <td></td> when there is not number inserted.

_______________________________________________________

else {

document.write("<td></td>");

}

The above part of the script is the one not working.

When the person does not type in a number coresponding to a foto, then the browser shows a bad link icon. Is there is another symbol or anything else to type in for the browser to show nothing in that place?
Copy linkTweet thisAlerts:
@steelersfan88Sep 12.2004 — Codeif (/^d+$/.test({@Foto2@})) {
document.write("&lt;td&gt;&lt;img src="{@Foto2@}.JPG"&gt;&lt;/td&gt;");
}
else {
document.write("&lt;td&gt;&lt;/td&gt;");
}
If only you didn't use the {@Foto2@} to confuse us all ...

or, you could test it against a number of good photos:if ({@Foto2@}.isPhoto()) {
document.write("&lt;td&gt;&lt;img src="{@Foto2@}.JPG"&gt;&lt;/td&gt;");
}
else {
document.write("&lt;td&gt;&lt;/td&gt;");
}

String.prototype.isPhoto = function() {
var good = [0,1,2,3,4];
for(var i=0;i&lt;good.length;i++){if(good[i]=this)return true;}
return false;
}
Dr. Script
Copy linkTweet thisAlerts:
@NedalsSep 12.2004 — [i]Originally posted by Pantera [/i]

[B]The above script works perfectly, the person writes in a number and the browser shows the foto. If they dont write in a number, the browser shows a bad link icon, this icon is what i am trying to get rid of by geting the browser to read <td></td> when there is not number inserted.[/B][/QUOTE]

If you enter anything, other than the symbol '#', your script will attempt to display an image. If you have a 5.jpg image it will be displayed. If you happened to have a 'anychar.jpg' image, and you were to enter 'anychar', it would also display that image.

Did you try the last script I gave you? It should do exactly what you want. (Only display an image if you enter a number)
Copy linkTweet thisAlerts:
@steelersfan88Sep 12.2004 — Although a user could enter 521067 and expect a picture ...
Copy linkTweet thisAlerts:
@NedalsSep 12.2004 — [i]Originally posted by steelersfan88 [/i]

[B]Although a user could enter 521067 and expect a picture ... [/B][/QUOTE]
That's true, but the OP did not supply a range of numbers.

That can be more easily done with...

var num = "{@Foto2@}"; // whatever this is!

if (/^(1|2|3|4|...|524)$/.test(num)) { // add whatever you need

document.write("<td><img src="{@Foto2@}.JPG"></td>");

} else {

document.write("<td></td>");

}
Copy linkTweet thisAlerts:
@steelersfan88Sep 12.2004 — Or the longer, less efiecent, BUT easier-to-modify-in-my-opinion way ;D
Copy linkTweet thisAlerts:
@PanteraauthorSep 12.2004 — Ok, got it to work. This script works perfectly.

[COLOR=red]

<html>

<head></head>

<body>

<table>

<tr>

<td>

<script type="text/javascript" language="JavaScript">

var Foto1 = "{@NumeroDaFoto1@}";

if (Foto1 != "") {

document.write("<img src="" + Foto1 + ".JPG">");

}

else {

document.write("");

}

</script>

</td>

<td>

<script type="text/javascript" language="JavaScript">

var Foto2 = "{@NumeroDaFoto2@}";

if (Foto2 != "") {

document.write("<img src="" + Foto2 + ".JPG">");

}

else {

document.write("");

}

</script>

</td>

</tr>

</table>

<br>

<table>

<tr>

<td>

<script type="text/javascript" language="JavaScript">

var Foto3 = "{@NumeroDaFoto3@}";

if (Foto3 != "") {

document.write("<img src="" + Foto3 + ".JPG">");

}

else {

document.write("");

}

</script>

</td>

<td>

<script type="text/javascript" language="JavaScript">

var Foto4 = "{@NumeroDaFoto4@}";

if (Foto4 != "") {

document.write("<img src="" + Foto4 + ".JPG">");

}

else {

document.write("");

}

</script>

</td>

</tr>

</table>

</body>

</html>

[/COLOR]
Copy linkTweet thisAlerts:
@steelersfan88Sep 12.2004 — very good ?
Copy linkTweet thisAlerts:
@NedalsSep 12.2004 — Happy to hear you got it working, but it's not exactly what you asked for.
If I write a NUMBER in the program where{@FOTO1@} applies, the program converts it to <td><img src="1.JPG"></td>[/quote]In your solution; if I write a LETTER, what do you expect? The program will convert it to <td><img src="A.JPG"></td>. Is that what you want?
×

Success!

Help @Pantera spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.28,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...