Jump to content


Photo

focusing on a div


  • Please log in to reply
6 replies to this topic

#1 spyke01

spyke01
  • Members
  • PipPipPip
  • Advanced Member
  • 74 posts

Posted 20 September 2006 - 08:28 PM

i have a div that i need to focus the page on so that the user can see their new comment flashing. I am using scriptaculous from script.aculo.us

The div:
<div id="11" class="comment" onload="setforcus(document.11); new Effect.Highlight(this); new Effect.Highlight(this);">
	<a href="http://www.fasttracksites.com">paden</a><br />
	<small>Posted on Sep 20, 2006</small><br /><br />
	asdasd
</div>

heres the full page: http://www.fasttrack...=viewentry&id=1

the page just stays at the top, any ideas?

[a href="http://www.fasttracksites.com" target="_blank"]Cheap PHP Hosting[/a]

#2 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 21 September 2006 - 12:45 AM

What's setfocus()?
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.

#3 spyke01

spyke01
  • Members
  • PipPipPip
  • Advanced Member
  • 74 posts

Posted 21 September 2006 - 01:01 AM

from what i saw on google you can do setfocus(document.item) instead of document.item.focus() i tried both ways however to no avail

[a href="http://www.fasttracksites.com" target="_blank"]Cheap PHP Hosting[/a]

#4 obsidian

obsidian
  • Staff Alumni
  • Advanced Member
  • 3,202 posts
  • LocationSeattle, WA

Posted 21 September 2006 - 01:13 AM

you're referring to document.l1, but it's your ID that is l1, and when you refer to your elements in javascript, it refers to the NAME. to focus on what you're after, you'll want to use this:
<body onload="document.getElementById('l1').focus()">

also, a div doesn't have an onload trigger, only the document (body) has that. i'm not sure if the div can take a focus or not, but it's worth a try.
You can't win, you can't lose, you can't break even... you can't even get out of the game.

<?php
while (count($life->getQuestions()) > 0)
{   $life->study(); } ?>
  LINKS: PHP: Manual MySQL: Manual PostgreSQL: Manual (X)HTML: Validate It! CSS: A List Apart | IE bug fixes | Zen Garden | Validate It! JavaScript: Reference Cards RegEx: Everything RegEx

#5 spyke01

spyke01
  • Members
  • PipPipPip
  • Advanced Member
  • 74 posts

Posted 21 September 2006 - 01:19 AM

if a div wont take a focus, how can i move down the page to a section without using an "a name" tag?

[a href="http://www.fasttracksites.com" target="_blank"]Cheap PHP Hosting[/a]

#6 obsidian

obsidian
  • Staff Alumni
  • Advanced Member
  • 3,202 posts
  • LocationSeattle, WA

Posted 21 September 2006 - 01:43 AM

well, with the id already set, you can refer to a div the same way you would with an anchor tag. for instance, if your div has an id of "div03", you can drop down to it by hitting a link with the href of "#div03". so, you just need to reference the div id instead. here is a quick PHP script that will generate trash content that you can play with and see how they react:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<style type="text/css">
body {
	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-size: 11px;
}

div {
	border: 1px solid #9EB9CF;
	margin: 10px;
	padding: 10px;
}
</style>
</head>

<body>
<?php
$links = array();
for ($i = 0; $i < 20; $i++) {
	$links[] = sprintf("<a href=\"#div%02d\">$i</a>", $i);
}
echo implode(" | ", $links);

for ($i = 0; $i < 20; $i++) {
	printf("<div id=\"div%02d\">\n", $i);
	echo "<h1>Div $i</h1>\n";
	for ($j = 0; $j < 15; $j++) {
		echo ($j + 1) . "<br />\n";
	}
	echo "</div>\n";
}
?>
</body>
</html>


You can't win, you can't lose, you can't break even... you can't even get out of the game.

<?php
while (count($life->getQuestions()) > 0)
{   $life->study(); } ?>
  LINKS: PHP: Manual MySQL: Manual PostgreSQL: Manual (X)HTML: Validate It! CSS: A List Apart | IE bug fixes | Zen Garden | Validate It! JavaScript: Reference Cards RegEx: Everything RegEx

#7 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 21 September 2006 - 01:15 PM

Almost everything can take focus, at least in IE, if it's visible.
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users