Home > front end >  Submit button sends me to the top of the page
Submit button sends me to the top of the page

Time:02-01

Firstly I'd like to say sorry about my bad english .

I want to say that before of creating this topic, I already checked other topics on here and tried solutions offered there but for me didn't work.

So, I have on my page at the bottom, a form which verify either the domain inserted in the form field is available or not.

So the HTML code is this:

<div >
      <div >
        <form action="#rezultat" method="GET" id="rezultat">
          <input type="text" name="domain" style="border: 0;padding: 4px 8px;width: calc(100% - 100px);" placeholder="Exemplu: numedorit.ro sau numedorit.eu" required><input type="submit" value="Verifica">
        </form>
      </div>
    </div>

The action of the form doesn't have any .php file because the php code is in the same file with the above HTML and the code is:

<?php
          error_reporting(0);
          if(isset($_GET['domain'])){
            $domain = $_GET['domain'];
            if ( gethostbyname($domain) != $domain ) {
                echo '<center><strong><font color="red">Denumirea selectata nu este disponibila..</font></strong></center>';
            }
            else {
                echo '<center><strong><font color="green">Denumirea selectata este disponibila..</font></strong></center>';
            }
          }
        ?>

My problem occurs when I press the submit button because it sends me to the top of the page instead of sending me to the "#rezultat" anchor how do I plan.

I used that anchor because this is how I read on a topic here but it just doesn't work. What I do notice is that after I press the submit button and it sends me to the top of the page, on the address bar I see:

http://********.ro/?domain=domain1234asd.com#rezultat

Where domain1234asd.com is the domain name I just checked if it is available or not. The true is that my php code returns correctly either the domain is available or not and it returns me the correct html code with the result.

Thank you in advance for your replies.

EDIT: @brombeer just gave me a good answer, the ' action="#rezultat" ' doesn't sends me to the anchor #rezultat because that anchor is the last element on the page, very down. (IDK WHY ????? His comment is not there anymore, even if it was the only one correct ???????? omg..)

As a test purpose, I just set a new anchor somewhere in the middle of the page and it works good. So the new question is how can I set the ' action="#rezultat" ' to send me to the ID 'rezultat' if this element is the last one on my page ??......

CodePudding user response:

Hash character in URL use for navigate item which has id value equal to hash it is called URI Fragmentation. In your case rezultat when browser sees #rezultat in the url it tries to find the element with id="rezultat" if there is no element with that id browser send you top of the page. So instead of using #rezultat use it http://********.ro/domain=domain1234asd.com&hash=rezultat like this

CodePudding user response:

Take a look at this line,

     <form action="#rezultat" method="GET" id="rezultat">

You are sending your data to a page reference. This is why you cannot submit the data. You have to point this action to the link which enters your php get data .

What is happening here?

  • When you are clicking submit it is getting you to the portion of the page where id is written/specified.
  •  Tags:  
  • Related