skip to Main Content

Im writting a code for my assigment "So,im now at view profile page when i click the button it will redirect to the update profile page when I hover the button the url is right but the button still stay at the same page" This is my code

    <div class="btn-block">
      <button type="button" value="back" onclick="location.href='homepage.html'">Back</button>
      <?php 
      echo '<a href="updateprofile.php?editid='.$edit_id.'" class="edit" title="Edit" data-toggle="tooltip"><button>Apply</button></a>'
      
    ?>
      </div>

I home somebody could fix this

3

Answers


  1. It is improper to nest a and button inside either the same or the other element. You could likely achieve a better result by using CSS to style the a instead of relying on JavaScript to make a link from the buttons.

    <button type="button" value="back" onclick="location.href='updateprofile.php?editid=<?= $edit_id ?>'">Apply</button>
    
    Login or Signup to reply.
  2. Add javascript: before your javascript in the onclick attribute like the following.

    <button type="button" value="back" onclick="javascript:location.href='homepage.html'">Back</button>
    

    See Codepen to see this working.
    https://codepen.io/hiroshisan/pen/ZEqjbyQ

    <div class="btn-block">
      <button type="button" value="back" onclick="javascript:location.href='homepage.html'">Back</button>
      <?php echo '<a href="updateprofile.php?editid='.$edit_id.'" class="edit" title="Edit" data-toggle="tooltip"><button>Apply</button></a>' ?>
    </div>
    
    Login or Signup to reply.
  3. Instead of using onclick="location.href='homepage.html'" you can use onclick="window.location='homepage.html'". This is how I redirect using a button.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search