1

I wanna switch this code:

<a href="selectare_gen.php" target="continut">Inapoi</a>

With a button. I want a button who redirect to ”selectare_gen.php” I tried:

<button onclick="location.href='selectare_gen.php'">Inapoi</button>

But all it does is refreshing the current page..

MSergiu
  • 33
  • 1
  • 6

3 Answers3

0

It should be

<button type="reset" onclick="location.href='selectare_gen.php'">
    Inapoi
</button>

The type="reset" is a workaround to prevent the browser from interpreting the button as a form element which causes the reload.

arkascha
  • 41,620
  • 7
  • 58
  • 90
  • 1
    Type `button` would be a better solution as it "[Does nothing](https://www.w3.org/TR/2011/WD-html5-20110525/the-button-element.html#the-button-element)". No need for a workaround. :) – Ivar May 24 '16 at 14:29
0

Check this link over here. It should answer your question.

How to create an HTML button that acts like a link?

Community
  • 1
  • 1
Adrian Chelu
  • 1
  • 1
  • 3
0

Many browsers think that the <button> tag will cause a submit that's why it's appearing to just refresh the page. If you use an input type="button" it wouldn't have this effect:

<input type="button" onclick="window.location='selectare_gen.php';" value="Inapoi" />
Avitus
  • 15,640
  • 6
  • 43
  • 53
  • The reason why many browsers think that, is because "[The missing value default is the Submit Button state.](https://www.w3.org/TR/2011/WD-html5-20110525/the-button-element.html#the-button-element)". – Ivar May 24 '16 at 14:34