Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

load picture based on variable

Status
Not open for further replies.

endoflux

Technical User
Joined
Aug 6, 2001
Messages
227
Location
US
I'm a real hack at most things in programming, so bear with me; Javascript may not even be the best way to do this:

I have an html table with 7 columns. Each column contains a picture of an arrow. What I want to accomplish is to have only 1 arrow appear, depending on a value in a variable, file, or other easily-changable item. This way, I can change the value from a 1 to a 2, and the arrow will display in the second column instead of the first, etc.

My questions are:

1-- how to I code the pictures to only show up when their value is present

2-- what is the easiest method to change the value without actually modifying code all the time?

Thanks in advance!

<tr>
<td height=37 width=44 valign="top" align="center"><center></center></td>
<td height=37 width=44 valign="top" align="center"><center></center></td>
<td height=37 width=48 valign="top" align="center"><center></center></td>
<td height=37 width=48 valign="top" align="center"><center></center></td>
<td height=37 width=48 valign="top" align="center"><center><IMG ALT="^" SRC="images/arrow.gif"></center></td>
<td height=37 width=76 valign="top" align="center"><center></center></td>
</tr>
 
The best way would be to use server-side code to achieve this. This would then open up the possibility of querying a txt file, database etc to read the value.

Take a google at php or asp (depends on what you have available to you)... you'll quickly see how to this kind of thing I reckon.

Cheers,
Jeff

[tt]Jeff's Page @ Code Couch
[/tt]

What is Javascript? FAQ216-6094
 
This worked out well; you pointed me exactly where I needed to go! PHP worked out great-- I stored the value in a txt file, and called that value with the "fopen" function. I was able to change the value in the file with the "Fput" function.

// page to change the image location (admin.html):

Enter the New Image Location:
<FORM ACTION="postthreat.php" method=post>
<input type="text" name="lvl" size="3" maxlength="1"><br><br>
<input type="submit" value="Submit">
</form>

// page to post change to txt file (postthreat.php):

<?php
$lvl = $_POST['lvl'];

$postlvl = fopen("lvl.txt", "w+");
fputs($postlvl, $lvl);
fclose($postlvl);
?>


// code called within site:

<?php
$getcurlvl = fopen("lvl.txt", "r");
$curlvl = fgets($getcurlvl, 2);
fclose($getcurlvl);
?>


<?php
if ($curlvl == "1") {
?>
<IMG ALT="^" SRC="images/arrow.gif">
<? } else { print ' ';} ?>
</center></td>

<td height=37 width=44 valign="top" align="center"><center>
<?php
if ($curlvl == "2") {
?>
<IMG ALT="^" SRC="images/arrow.gif">
<? } else { print ' ';} ?>
</center></td>
<td height=37 width=48 valign="top" align="center"><center>
<?php
if ($curlvl == "3") {
?>
<IMG ALT="^" SRC="images/arrow.gif">
<? } else { print ' ';} ?>
</center></td>
<td height=37 width=48 valign="top" align="center"><center>
<?php
if ($curlvl == "4") {
?>
<IMG ALT="^" SRC="images/arrow.gif">
<? } else { print ' ';} ?>
</center></td>
<td height=37 width=48 valign="top" align="center"><center>
<?php
if ($curlvl == "5") {
?>
<IMG ALT="^" SRC="images/arrow.gif">
<? } else { print ' ';} ?>
</center></td>
<td height=37 width=76 valign="top" align="center"><center>
<?php
if ($curlvl == "6") {
?>
<IMG ALT="^" SRC="images/arrow.gif">
<? } else { print ' ';} ?>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top