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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Error in IE but not firefox

Status
Not open for further replies.

the44chris

Programmer
Aug 6, 2007
5
US
We are having a problem with adding products into our portfolio only in IE. In firefox it works great, but in IE clicking the “add to portfolio” button on product pages yields no results besides an “error on page” notification. The error reads…

Line: 42
Char: 5
Error: Object doesn’t support this property or method
Code: 0
URL: points to our order_page.pl with a reference to the specific product

A basic rundown of how our portfolio functions…
Product pages are dynamically generated with an order_page.pl perl script. On the product page there is a link to add the product to a portfolio, which is handled by a show_favorites.pl perl script. I don’t know in which perl script the error resides.

I have tried setting all ie security preferences to the absolute bare minimum and the problem still exists.

Any help in determining how to fix this problem would be greatly appreciated.

The code for the order_page.pl script(doubt you need the template files too):

Code:
#!/usr/bin/perl -w
require '.pm';
use CGI;
use CGI::Carp 'fatalsToBrowser';
use DBI;
$dbh = DBI->connect("dbi:mysql:", "", "", { RaiseError => 1});
$cgq = new CGI;
print "Content-type: text/html\n\n";
my $photo_id = $cgq->param('photo_id');
if (!$photo_id) {
	print "<HTML><HEAD><TITLE>Error</TITLE></HEAD>";
	print "<BODY>I'm sorry, but a photo_id is required...</BODY></HTML>";
	exit();
}
my %prices;
sub hashValueAscendingNum {
   $prices{$a} <=> $prices{$b};
}
my $sth = $dbh->prepare("select * from _tmp where photo_id='$photo_id'");
$sth->execute();
my $results = $sth->fetchrow_hashref();
$params{'photo_id'} = $photo_id;
$params{'_name'} = $results->{'name'};
$params{'category'} = $results->{'category'};
$params{'material'} = $results->{'material'};
$params{'quality'} = $results->{'quality'};
$params{'made_in'} = $results->{'made_in'};
$params{'collection'} = $results->{'collection'};
$params{'description'} = $results->{'description'};
$params{'descr2'} = $results->{'descr2'};
$params{'designer'} = $results->{'made_in'};
$params{'picture'} = $results->{'picture'};
$params{'large_pic'} = $results->{'large_pic'};
$params{'keywords'} = "".$results->{'name'}.", ".$results->{'category'}.", ".$results->{'material'}.", ".$results->{'quality'}.", ".$results->{'made_in'}.", ".$results->{'collection'};
$params{'meta_description'} = $results->{'description'};
$params{'meta_description'} =~ s/[\n\r"]//g;
print_tpl("template/order_page_top.tpl", "", %params);
my $sth2 = $dbh->prepare("select name, category, cart2.photo_id from cart as cart1, cart as cart2,_tmp where cart1.photo_id='$photo_id' and cart1.cart_id = cart2.cart_id and _tmp.photo_id = cart2.photo_id and cart2.photo_id!='$photo_id' group by 1 limit 3;");
#$sth2->execute();
if (0 && $sth2->rows) {
	print <<ENDHTML;
                      <tr>
                        <td colspan="4" bgcolor="#990000">
                          <font color=#ffffff face="Verdana, Arial, Helvetica" size="1">&nbsp;<b>Others who bought this item has also bought...
                            </font>
                        </td>
	                </tr>
ENDHTML
}
my $old_photo_id = $cgq->param('photo_id');
while (0 && (my $row_arr = $sth2->fetchrow_hashref())) {
	$cgq->param('photo_id', $row_arr->{'photo_id'});
	print "<tr>";
	print "<td><font color=#000000 face=\"Verdana, Arial, Helvetica\" size=\"2\"><b><a href=\"".$cgq->self_url()."\">".$row_arr->{'name'}."</a></b></font></td>";
	print "<td><font color=#000000 face=\"Verdana, Arial, Helvetica\" size=\"2\"><b>".$row_arr->{'category'}."</b></font></td>";
	print "</tr>";
}
$cgq->param('photo_id', $old_photo_id);
$_name = $params{'_name'};
print <<ENDHTML;
                      <tr>
                        <td colspan="4" height="60" bgcolor="#990000">
                          <p><font
                        color=#ffffff face="Verdana, Arial, Helvetica" size="1">&nbsp;<b>Product
                            Shown: </b></font><font face="Verdana, Arial, Helvetica" size="2" color="#FFCC33"><b>
                            &quot;$_name&quot; &nbsp;</b></font><font
                        color=#ffffff face="Verdana, Arial, Helvetica"><br>
                            </font></p>
                          <p>&nbsp;</p>
                        </td>
	                </tr>
ENDHTML
print "<input type=\"hidden\" name=\"photo_id\" value=\"".$cgq->param('photo_id')."\">";
if (!$cgq->param('action')) {
	print "<input type=\"hidden\" name=\"action\" value=\"add_\">";
}
for(my $i=1; $i<=15; $i++) {
	my $size = $results->{"size$i"};
	my $price = $results->{"price$i"};
	$prices{$size} = scalar $price;
	$prices_loc{$size} = scalar $i;
	if (($prices{$size}) && ($results->{'sale'})) {
	  $prices_sale{$size} = calculate_sale($price, $results->{'sale'});
	}
}
my $price_count = 0;
foreach $size (sort hashValueAscendingNum (keys(%prices))) {
	if ($size) {
		$price_count++;
		print "<tr bgcolor=\"#faf2e0\">";
		print "<td width=\"210\" height=\"2\"><font color=\"#000000\" face=\"arial, verdana, helvetica, sans-serif\" size=\"2\"><b>$size</b></font></td>";
		print <<ENDHTML;
	                        <td colspan="3" width="120" bgcolor="#faf2e0" height="2"><font
	                        face="arial, verdana, helvetica, sans-serif"
	                        size=2>
ENDHTML
		print "<input name=\"option_value\" class=\"sizeRadioSelect\" type=\"radio\" rel=\"$size\" value=\"".$prices_loc{$size}." \"".($price_count == 1?" checked":"").">";
		if ($prices_sale{$size}) {
		  print "<font color=#990000 face=\"arial, verdana, helvetica, sans-serif\"><b>\$".$prices_sale{$size}."</font> <font face=\"arial, verdana, helvetica, sans-serif\"><strike>";
		}
		print "\$$prices{$size}</font></strike></b></td></tr>";
	}
}
if ($params{'large_pic'} && (-e "/home//[URL unfurl="true"]www/".$params{'large_pic'}))[/URL] {
	$params{'large_pic_code'} = $params{'large_pic'};
} else {
	$params{'large_pic_code'} = $params{'picture'};
}
$params{"self_url"} = $cgq->self_url();
print_tpl("template/order_page_bottom.tpl", "", %params);



for the show_favorites.pl page……..

Code:
#!/usr/bin/perl -w
require '.pm';
use CGI;
use CGI::Carp 'fatalsToBrowser';
use DBI;
connect_db();
$cgq = new CGI;
$showFrame = TRUE;
my $user_id = check_login();
if (!$user_id) {
	print $cgq->header(-status=>"302 Moved", -location=>"/Signin.htm?finish=".$cgq->self_url());
	exit;
}
print "Content-type: text/html\n\n";
if (($cgq->param('action') eq "delete") && ($cgq->param('fav_id') ne "")) {
	$dbh->do("delete from favs where user_id='".$user_id."' and id='".$cgq->param('fav_id')."'");
} elsif (($cgq->param('action') eq "add") && ($cgq->param('photo_id') ne "")) {
	$dbh->do("insert into favs set user_id='".$user_id."', photo_id='".$cgq->param('photo_id')."', size=".$dbh->quote($cgq->param('size')));
} elsif (($cgq->param('action') eq "update")) {
	$totalRows = $cgq->param('rowCount');
	$result = TRUE;
	$runQuery = FALSE;
	for($i=1;$i<=$totalRows;$i++) {
		$rowFavID = $cgq->param('favID' . $i);
		$rowComment = $dbh->quote($cgq->param('rowComment' . $i));
		$rowQty = $cgq->param('rowQty' . $i);
		$rowSize = $dbh->quote($cgq->param('rowSize' . $i));
		$rowRemove = $cgq->param('removeID' . $i);
		if ($rowRemove) {
			$query = "delete from favs";
			$runQuery = TRUE;
		} else {
			if (($rowComment ne "''") || ($rowSize ne "''") || ($rowQty ne "")) {
				$query = "update favs set";
				if ($rowComment ne "''") {
					$query = $query . " comment=".$rowComment;
				}
				if ($rowQty) {
					if ($rowComment ne "''") {
						$query = $query . ",";
					}
					$query = $query . " qty='" . $rowQty . "'";
				}
				if ($rowSize ne "''") {
					if ($rowComment ne "''" || $rowQty) {
						$query = $query . ",";
					}
					$query = $query .  " size=".$rowSize;
				}
				$runQuery = TRUE;
			}
		}
		if ($runQuery) {
			$query = $query . " where id='".$rowFavID."'";
			$locResult = $dbh->do($query);
			if (!$locResult) {
				$result = FALSE;
			}
		}
	}
	if ($result) {
		print "{'response':'1', 'message':'Update succesfull.', 'query':".$printQuery."}";
	} else {
		print "{'response':'0', 'message':'Failed to update.'}";
	}
	exit();
}
$query_sizes = "";
for($i=1;$i<15;$i++) {
	$query_sizes = $query_sizes."size".$i.", ";
}
$query = "select _tmp.photo_id, favs.id as fav_id, favs.qty as fav_qty, favs.size as fav_size, favs.comment as fav_comment, name, category, collection, ".$query_sizes." thumb_pic from _tmp, favs where _tmp.photo_id=favs.photo_id and favs.user_id=$user_id";
my $sth = $dbh->prepare($query);
$sth->execute();
$params{'rowCount'} = $sth->rows();
if ($showFrame) {
	print_tpl("template/portfolio_top.tpl", "", %params);
}
$x = 1;
while (my $row_arr = $sth->fetchrow_hashref) {
		$params{'rowID'} = $x;
		$params{'fav_id'} = $row_arr->{'fav_id'};
		$params{'photoID'} = $row_arr->{'photo_id'};
		$params{'thumbnail'} = $row_arr->{'thumb_pic'};
		$params{'itemName'} = $row_arr->{'name'};
		$params{'itemCategory'} = $row_arr->{'category'};
		$params{'itemCollection'} = $row_arr->{'collection'};
		$params{'itemSize'} = $row_arr->{'fav_size'};
		$params{'rowQTY'} = $row_arr->{'fav_qty'};
		$params{'rowComment'} = $row_arr->{'fav_comment'};
		if ($params{'rowComment'} eq "") {
			$params{'rowComment'} = "Click here to add a comment...";
		}
		$itemSizeOptions = "";
		for($i=1;$i<15;$i++) {
			if (!($row_arr->{'size'.$i} eq "")) {
				if ($row_arr->{'size'.$i} eq $row_arr->{'fav_size'}) {
					$itemSizeSelected = ' selected="selected"';
				} else {
					$itemSizeSelected = "";
				}
				$itemSizeOptions = $itemSizeOptions . "<option".$itemSizeSelected.">".$row_arr->{'size'.$i}."</option>\n";
			}
		}
		$params{'itemSizeOptions'} = $itemSizeOptions;
		print_tpl("template/portfolio_item.tpl", "", %params);
		$x++;
}
if ($showFrame) {
	print_tpl("template/portfolio_bottom.tpl");
}
 
This sort of error should be made obvious by examining the HTML that is sent to the page. After all, it is the browser that is reporting the error.

Chances are either some perl slipping into the page, or more likely, errant javascript.

At least, that's where I'd start.
 
Looks like a JavaScript error. Instead of looking in your Perl code (which would be useless since, IE doesn't know what your code is, so it's obviously not talking about that), look at the page source that gets sent to IE when your CGI script runs.

The line number and character would be within a block of JavaScript code. Although, I didn't seem to find a <script> tag in your code anywhere. Is this the full code? The message that IE is giving you looks a lot like a JavaScript problem.

-------------
Cuvou.com | My personal homepage
Project Fearless | My web blog
 
Code:
[b]print_tpl("template/order_page_top.tpl", "", %params);[/b]

I'm thinking this template may contain the javascript that is causing the error.
Again, check the HTML that the browser is getting.
It may be that the params hash is not being filled as expected by the template.
 
That particular template makes reference to a few external javascript files. I found the javascript file that provides the mechanism for adding products to the portfolio from the product pages.

I also ended up comparing the html generated by the two different browsers. Word's compare feature found zero differences, which I found to be kind of odd.


I know this is the perl forum, but perhaps somebody can pick out a quick mistake in this javascript that could be causing this...

Code:
function initItemPage() {
                window.addEvent('domready', function(e) {
                                                printTable();                                                $('addToFavorites').addEvent('click', function(e) {
                                                                var ev = new Event(e);
                                                                ev.stop();
                                                                var photoID = ev.target.getParent().getProperty('rel');
                                                                var urlPrefix = "/cgi-bin/show_favorites.pl?";
                                                                var sizeSelect = null;
                                                                $ES('.sizeRadioSelect').each(function(el) {
                                                                                if (el.getValue()) {
                                                                                                sizeSelect = el.getProperty('rel');
                                                                                }
                                                                });
                                                                var urlParams = new Hash();
                                                                urlParams.set('action', 'add');
                                                                urlParams.set('photo_id', photoID);
                                                                urlParams.set('size', sizeSelect);
                                                                var queryString = Object.toQueryString(urlParams.obj);
                                                                var resultUrl = urlPrefix + queryString;
                                                                window.location = resultUrl;
                                                });
                });
}
 
Each browser and each browser version will support javascipt a bit differently. The best place to ask is the javascripting forum.

------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
Quick scan of that makes me think some of the perl code/template code is malformed:

Code:
$ES('.sizeRadioSelect')........

$ES looks like perl code.

Find where that line is output in the script or the template (tpl) file and you should have your culprit.
 
I also ended up comparing the html generated by the two different browsers. Word's compare feature found zero differences, which I found to be kind of odd

Not at all odd.

Unless your server-side scripts are examining the User-Agent setting of the request, and providing different HTML per browser, the HTML will be identical.

What is different is the Object Models that the browsers employ. This means that certains methods and properties that are legal in one browser mean nothing to the other. Or even more subtle; your browsers' security settings may be configured differently from each other.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top