title: How to scroll to a particular div after reloading the page when the submit button is clicked?
body: <p>Iam trying to do something fancy. I have successfully written code to show results from database when a small form is filled and submit button is clicked.The results are shown right under the form. But I feel it would be nice if the page is automatically scrolled down to the div containing the results for the filled form. I suppose i have to use jquery or ajax for that. Since I have no knowledge in them I searched the internet for copy pasting the code. But none of them works.  </p>
  
  <p>When the submit button is clicked,the page will reload to fetch results from database.I have got the code for scrolling down to a div when page reloads from net,but the problem with that is..the scrolling happens even thou submit button is not clicked. So can someone gimme the code for scrolling down to a div only  when the submit button is clicked and after when the page is reloaded.  </p>
  
  <p>the code is something like this  </p>
  
  <pre><code>&lt;form name="searchdonor" action="" id="form" method="POST" align="center" enctype="application/x-www-form-urlencoded"&gt;  
  --- ------ ------  
  --- ------ ------  
  --- ------ ------
  
  &lt;/form&gt;  
  &lt;input type="submit" name="submit" id="submit" value="Submit"  onclick="return(searchval()); "&gt; 
  //the div i want to scroll down is below one 
  &lt;div class="col-sm-8" id="what"&gt;
  &lt;/div&gt;  
  </code></pre>
  
  <p><strong>here's the complete code in html and php-mysqli</strong>  </p>
  
  <pre><code>&lt;div class="col-sm-4"&gt;
           &lt;h1 class="register-title"&gt;Search a Donor&lt;/h1&gt;
                &lt;div id="wrapper"&gt;
                &lt;div id="chatbox"&gt;
        &lt;form name="searchdonor" action="" id="form" method="POST" align="center" enctype="application/x-www-form-urlencoded"&gt;
          &lt;table id="results"&gt;
                  &lt;tr&gt;&lt;td&gt;&lt;h4&gt;Country:&lt;/h4&gt;&lt;/td&gt;&lt;td&gt;&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp
                   &lt;select id="slct1" name="country" onchange="populate1(this.id,'slct2')"&gt;
                    &lt;option value=""&gt;--Select--&lt;/option&gt;
                    &lt;option value="India"&gt;India&lt;/option&gt;
                   &lt;/select&gt;&lt;/td&gt;&lt;/tr&gt;
                  &lt;tr&gt;&lt;td&gt;&lt;h4&gt;State:&lt;/h4&gt;&lt;/td&gt;&lt;td&gt;&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp
                   &lt;select id="slct2" name="state" onchange="populate2(this.id,'slct3')"&gt;
                    &lt;option value=""&gt;--Select--&lt;/option&gt;
                   &lt;/select&gt;&lt;/td&gt;&lt;/tr&gt;
                  &lt;tr&gt;&lt;td&gt;&lt;h4&gt;District:&lt;/h4&gt;&lt;/td&gt;&lt;td&gt;&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp
                   &lt;select id="slct3" name="district" onchange="populate3(this.id,'slct4')"&gt;
                    &lt;option value=""&gt;--Select--&lt;/option&gt;
                   &lt;/select&gt;&lt;/td&gt;&lt;/tr&gt;
                  &lt;tr&gt;&lt;td&gt;&lt;h4&gt;City:&lt;/h4&gt;&lt;/td&gt;&lt;td&gt;&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp
                   &lt;select id="slct4" name="city"&gt;
                    &lt;option value=""&gt;--Select--&lt;/option&gt;
                   &lt;/select&gt;&lt;/td&gt;&lt;/tr&gt;
                  &lt;tr&gt;&lt;td&gt;&lt;h4&gt;Blood group:&lt;/h4&gt;&lt;/td&gt;&lt;td&gt;&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp
                   &lt;select name="bloodgroup"&gt;
          &lt;option value=""&gt;--Select--&lt;/option&gt;
          &lt;option value="A+"&gt;A+&lt;/option&gt;
          &lt;option value="A-"&gt;A-&lt;/option&gt;
          &lt;option value="B+"&gt;B+&lt;/option&gt;
          &lt;option value="B-"&gt;B-&lt;/option&gt;
          &lt;option value="O+"&gt;O+&lt;/option&gt;
          &lt;option value="O-"&gt;O-&lt;/option&gt;
          &lt;option value="AB+"&gt;AB+&lt;/option&gt;
          &lt;option value="AB-"&gt;AB-&lt;/option&gt;
                  &lt;/select&gt;&lt;/td&gt;&lt;/tr&gt;
  
        &lt;/form&gt;
        &lt;/table&gt;&lt;br /&gt;
  
      &lt;input type="submit" name="submit" id="submit" value="Submit"  onclick="return(searchval());"&gt;
      &lt;/div&gt;
  
  
                &lt;/div&gt;
           &lt;/div&gt;
  
           &lt;div class="col-sm-2"&gt;
           &lt;/div&gt;
       &lt;/div&gt;
       &lt;div class="dropdownwrap"&gt;
       &lt;?php 
       if(isset($_POST['submit'])){
  
                $country=$_POST['country'];
                $state=$_POST['state'];
                $district=$_POST['district'];
                $city=$_POST['city'];
                $bloodgroup=$_POST['bloodgroup'];
                ?&gt;
       &lt;div class="row"&gt;&lt;br /&gt;
          &lt;div class="col-sm-2"&gt;
          &lt;/div&gt;
          &lt;div class="col-sm-8" id="what"&gt;
          &lt;a class="what"&gt;&lt;/a&gt;
          &lt;?php echo "&lt;h4 align='center'&gt; Donors in &lt;b&gt;".$city."&lt;/b&gt; for &lt;b&gt;".$bloodgroup."&lt;/b&gt; are&lt;/h4&gt;";?&gt;
          &lt;/div&gt;
          &lt;div class="col-sm-2"&gt;
          &lt;/div&gt;
       &lt;/div&gt;
         &lt;div class="row"&gt;
          &lt;div class="col-sm-2"&gt;
          &lt;/div&gt;
          &lt;div class="col-sm-8"&gt;
            &lt;div class="table-responsive"&gt;
  
             &lt;table id="tablepaging" class="table" align="center"&gt;
              &lt;thead&gt;&lt;hr /&gt;
               &lt;tr&gt;
                  &lt;th&gt;&lt;b&gt;Full Name&lt;/b&gt;&lt;/th&gt;
                  &lt;th&gt;&lt;b&gt;Contact Number&lt;/b&gt;&lt;/th&gt;
               &lt;/tr&gt;
              &lt;/thead&gt;
              &lt;tbody&gt;
                &lt;?php 
  
  
                $connect = mysqli_connect('localhost', 'root', '', 'blood'); if (mysqli_connect_errno()) echo "Failed to connect to MySQL: " . mysqli_connect_error();
                $query="SELECT * FROM users WHERE country='$country' &amp;&amp; state='$state' &amp;&amp; district='$district' &amp;&amp; city='$city' &amp;&amp; bloodgroup='$bloodgroup' &amp;&amp; activity='available'";
                $result=mysqli_query($connect,$query) or die('Error, query failed');
                mysqli_close($connect);
                if (mysqli_num_rows($result) == 0) {
                echo"&lt;h3 align=\"center\"&gt;Sorry, No Donors Found&lt;/h3&gt;";
                }
                elseif($result)
                {
                while ($row = mysqli_fetch_array($result)){
  
                echo"&lt;tr&gt;";
                echo"&lt;td&gt;".$row["firstname"]."&amp;nbsp".$row["lastname"]."&lt;/td&gt;";
                echo"&lt;td&gt;".$row["phonenumber"]."&lt;br /&gt;".$row["secondnumber"]."&lt;/td&gt;";
                }
                echo"&lt;/tr&gt;";
  
                }}
                ?&gt;
              &lt;/tbody&gt;
             &lt;/table&gt;
              &lt;div id="pageNavPosition" align="center"&gt;&lt;/div&gt;
            &lt;/div&gt;
           &lt;/div&gt;
  
  
  
           &lt;div class="col-sm-2"&gt;
           &lt;/div&gt;
  
  
  &lt;/div&gt;       
  
  &lt;/div&gt;
  
  &lt;/div&gt;
  </code></pre>