...

View Full Version : Clicking submit scrolls the page to top



AshleyQuick
03-25-2005, 07:31 PM
When I enter a search term and click submit, the page scrolls to the top. I have this form field toward the bottom of a page so, when you click submit, is there a way the page will stay toward the bottom instead of scrolling all the way up?

Does this make sense?



<a href="http://news.yahoo.com" target="_blank">
<img src="http://us.i1.yimg.com/us.yimg.com/i/us/nws/th/main_142.gif" border="0">
</a>
<form action="<?php $PHP_SELF;?>" method="GET" name="yahoo_news">
<input type="text" size="50" name="p" value="<?php echo stripslashes($HTTP_GET_VARS['p']);?>">
<input type="submit" value="News Search">
</form>
<?php

if ($p) {
$p = str_replace(" ", "+", $HTTP_GET_VARS['p']);

$backend = "http://news.search.yahoo.com/usns/ynsearch/categories/news_story_search_rss/index.html?p=$p";

function startElement($parser, $tagName, $attrs)
{
global $insideitem, $tag;

if ($insideitem) {
$tag = $tagName;
} elseif ($tagName == "ITEM") {
$insideitem = true;
}
}

function characterData($parser, $data)
{
global $insideitem, $tag, $title, $description, $link, $pubDate;

if ($insideitem) {
switch ($tag) {
case "TITLE":
$title .= $data;
break;
case "DESCRIPTION":
$description .= $data;
break;
case "LINK":
$link .= $data;
break;
case "PUBDATE":
$pubDate .= $data;
break;
}
}
}

function endElement($parser, $tagName)
{
global $insideitem, $tag, $title, $description, $link, $pubDate;

if ($tagName == "ITEM") {
$trans_tbl = get_html_translation_table (HTML_ENTITIES);
$trans_tbl = array_flip ($trans_tbl);
$text = strtr ($description, $trans_tbl);

echo "<p style=padding-left:10px><b><a style='margin-left:-3' href='$link' target='_blank'>$title</a></b>";
echo "<br>";
echo "<i>$pubDate</i>";
echo "<br>";
echo "$text";
echo "</p>";

$title = $description = $link = $pubDate = $insideitem = false;
}
}

$xml_parser = xml_parser_create();

xml_set_element_handler($xml_parser, "startElement", "endElement");
xml_set_character_data_handler($xml_parser, "characterData");

$fp = fopen($backend, r);

while ($data = fread($fp, 4096)) {
xml_parse($xml_parser, $data, feof($fp))
or die(sprintf("XML error: %s at line %d",
xml_error_string(xml_get_error_code($xml_parser)),
xml_get_current_line_number($xml_parser)));
}

fclose($fp);

xml_parser_free($xml_parser);

?>
<a href="http://news.yahoo.com" target="_blank">
<img src="http://us.i1.yimg.com/us.yimg.com/i/us/nws/th/main_142.gif" border="0">
</a>

<form action="<?php $PHP_SELF;?>" method="GET" name="yahoo_news">
<input type="text" size="50" name="p" value="<?php echo stripslashes($HTTP_GET_VARS['p']);?>">
<input type="submit" value="News Search">
</form>

<?php



}

?>

Willy Duitt
03-25-2005, 08:11 PM
You are submitting the form to itself so it is reloading the page...
Try adding a named anchor...

.....Willy



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum