JavaScript and client side scripting.
Moderator: General Moderators
sunbedkid
Forum Newbie
Posts: 7 Joined: Fri Aug 27, 2004 9:33 am
Post
by sunbedkid » Fri Aug 27, 2004 9:33 am
feyd | Please use Code: Select all
tags when posting code. Read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
I have been utilizing OR real estate software (php). There is a small problem with the image swap in that with every image uploaded, you can attach a caption with a description, the image will change, but can't get the text to change.
Is there anyone who could solve this problem?
This is the code:
===============================================Code: Select all
function renderListingsMainImageJava($listingID)
{
// shows the main image
global $conn, $lang, $config, $style;
// grab the images
$listingID = make_db_extra_safe($listingID);
$sql = "SELECT ID, caption, description, file_name FROM " . $config['table_prefix'] . "listingsImages WHERE (listing_id = $listingID) ORDER BY rank LIMIT 0,1";
$recordSet = $conn->Execute($sql);
if ($recordSet === false)
{
log_error($sql);
}
$num_images = $recordSet->RecordCount();
if ($num_images > 0)
{
while (!$recordSet->EOF)
{
$file_name = make_db_unsafe ($recordSet->fields['file_name']);
$caption = make_db_unsafe ($recordSet->fields['caption']);
$description = make_db_unsafe ($recordSet->fields['description']);
echo "<center><img src="$config[listings_view_images_path]/$file_name" width="440" name="main"></center>";
if ($description == "")
{
$description = 'Listing #'.$file_name.'';
}
echo "<b>$description</b><br><br>";
$recordSet->MoveNext();
} // end while
} // end if ($num_images > 0)
} // end function renderListingsMainImageJava
function renderListingsImagesJava($listingID)
{
// shows the images connected to a given image
global $conn, $lang, $config, $style;
// grab the images
$listingID = make_db_extra_safe($listingID);
$sql = "SELECT ID, caption, description, file_name, thumb_file_name FROM " . $config['table_prefix'] . "listingsImages WHERE (listing_id = $listingID) ORDER BY rank";
$recordSet = $conn->Execute($sql);
if ($recordSet === false)
{
log_error($sql);
}
$num_images = $recordSet->RecordCount();
if ($num_images > 0)
{
echo "<td width="$style[image_column_width]" valign="top" class="row_main" align="center">";
while (!$recordSet->EOF)
{
$caption = make_db_unsafe ($recordSet->fields['caption']);
$description = make_db_unsafe ($recordSet->fields['description']);
$thumb_file_name = make_db_unsafe ($recordSet->fields['thumb_file_name']);
$file_name = make_db_unsafe ($recordSet->fields['file_name']);
$imageID = make_db_unsafe ($recordSet->fields['ID']);
// gotta grab the image size
$imagedata = GetImageSize("$config[listings_upload_path]/$thumb_file_name");
$imagewidth = $imagedata[0];
$imageheight = $imagedata[1];
$shrinkage = $config['thumbnail_width']/$imagewidth;
$displaywidth = $imagewidth * $shrinkage;
$displayheight = $imageheight * $shrinkage;
echo "<a href="javascript:void imgchange('$file_name');" onmouseover="imgchange('$file_name');" onmouseover="imgchange('$description');" onclick="this.blur();"> ";
echo "<img src="$config[listings_view_images_path]/$thumb_file_name" height="$displayheight" width="$displaywidth" alt="$caption"></a><br>";
echo "<b>$caption</b><br><br>";
$recordSet->MoveNext();
} // end while
echo "</td>";
} // end if ($num_images > 0)
} // end function renderListingsImagesJava
===============================================
Any help appreciated
Thanks.
feyd | Please use Code: Select all
tags when posting code. Read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Fri Aug 27, 2004 9:58 am
your imgchange function isn't here so:
obj.title is the only property I see in the Javascript reference that would affect it.
btw, java and javascript, two entirely different animals.
sunbedkid
Forum Newbie
Posts: 7 Joined: Fri Aug 27, 2004 9:33 am
Post
by sunbedkid » Fri Aug 27, 2004 10:06 am
As far as I am aware, the imgchange at the bottom of the quote is the function, I have changed this around quite a lot and basically that's the way it works at the moment albeit only changes the image and not the description.
Maybe the bit that you think is missing is what I need?
Thanks for your response.
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Fri Aug 27, 2004 10:38 am
you didn't post an imgchange javascript function.. Your code here:
Code: Select all
"<a href="javascript:void imgchange('$file_name');" onmouseover="imgchange('$file_name');" onmouseover="imgchange('$description');" onclick="this.blur();"> "is strictly calls, nothing more.
sunbedkid
Forum Newbie
Posts: 7 Joined: Fri Aug 27, 2004 9:33 am
Post
by sunbedkid » Fri Aug 27, 2004 10:50 am
In that case, how could I get it to work?
I did try experimenting with a javascript programme that I found on the web. I try adapting it to fit, but alas I am to inexperienced so my time was spent in vane.
At the moment the image swap works fine, is there a way I can modify this code to swap the text aswell?
Thanks
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Fri Aug 27, 2004 11:06 am
yes, you can modify the image swap function to do it.. however, you don't need 2 onmouseover's.. only 1 gets called, I believe..
post your imgchange function.
sunbedkid
Forum Newbie
Posts: 7 Joined: Fri Aug 27, 2004 9:33 am
Post
by sunbedkid » Fri Aug 27, 2004 11:39 am
I belive this is it:
<?php echo "<SCRIPT Language=\"JAVASCRIPT\"> function imgchange(name){if(document.images){document.main.src = \"$config[listings_view_images_path]/\" + name; } else { document.main.src = \"images/nophoto.gif\"; }}</SCRIPT>";
?>
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Fri Aug 27, 2004 12:09 pm
that code's kinda screwy... but anyways.. adding
Code: Select all
document.main.title = 'your description here';inside that if's true statement block should set the text. You can add an argument to the function to bring in the description from an "external" source.. i.e. each image swap call.
sunbedkid
Forum Newbie
Posts: 7 Joined: Fri Aug 27, 2004 9:33 am
Post
by sunbedkid » Fri Aug 27, 2004 12:42 pm
Does this look right to you?
Code: Select all
<?php echo "<SCRIPT Language="JAVASCRIPT"> function imgchange(name){if(document.images){document.main.src = "$config[listings_view_images_path]/" + name; }{document.main.title = "$config[listings_view_images_path]/" + name; } else { document.main.src = "images/nophoto.gif"; }}</SCRIPT>";
?>
?>
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Fri Aug 27, 2004 12:47 pm
that'll change the description to the url used for the image.. does that work for you?
sunbedkid
Forum Newbie
Posts: 7 Joined: Fri Aug 27, 2004 9:33 am
Post
by sunbedkid » Sat Aug 28, 2004 3:08 am
Sorry for the delay in responding - the server went down.
I tried the above change, but it seems to have stopped the image change completely.
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Sat Aug 28, 2004 3:10 am
Code: Select all
...gїlistings_view_images_path]/" + name; }{document.main.title....remove the braces }{ in that code.
sunbedkid
Forum Newbie
Posts: 7 Joined: Fri Aug 27, 2004 9:33 am
Post
by sunbedkid » Sat Aug 28, 2004 4:00 am
Teh image change works now, but the text still doesn't change.
The new code references the image file (I think). I need to be able to refernce the $description tag that associates the file the image is in.
Does that make sense? Or am I mistaken?
Last edited by
sunbedkid on Sat Aug 28, 2004 4:05 am, edited 1 time in total.
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Sat Aug 28, 2004 4:03 am
that's the only supported text change I see in the DOM.. so..