Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Jun 2002
    Location
    USA
    Posts
    308
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy Clicking submit scrolls the page to top

    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?

    Code:
    <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
    
       
    
    }
    
    ?>

  • #2
    Banned
    Join Date
    Sep 2003
    Posts
    3,620
    Thanks
    0
    Thanked 0 Times in 0 Posts
    You are submitting the form to itself so it is reloading the page...
    Try adding a named anchor...

    .....Willy


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •