Josiah Grubbs
Josiah Grubbs

Reputation: 1

Why is my button disappearing after being clicked

My button is acting the way I need it to except when it is clicked on it completely disappears. Why is it doing this?

<script type="text/javascript">
function randomlinks(){
    var myrandom=Math.round(Math.random()*6)
    var links=new Array()
    links[0]="https://abantutogether.org/"
    links[1]="https://abantutogether.org/about-us"
    links[2]="https://abantutogether.org/donate"
    links[3]="https://abantutogether.org/get-involved"
    links[4]="https://abantutogether.org/blog"
    links[5]="https://abantutogether.org/contact-us"
    links[6]="https://abantutogether.org/sponsor-a-child"
  
 
     window.open(links[myrandom])
}
</script>
<form>
<input type="image" src="https://i.postimg.cc/43PDgqnZ/Logo-Pix-Teller-1.png"  value="random link!" onClick="randomlinks()">
</form>

Upvotes: 0

Views: 34

Answers (1)

tonyfarney
tonyfarney

Reputation: 300

When you click the button another tab/browser window is opened and the page is being submitted. Is this the behavior you expect?

It sounds weird to me the form submission in this circumstance (there is no action attribute set in the form TAG) . Maybe you don't want to have this input inside a form, or alternatively you can just avoid the submmit by changing the onclick property as follow:

onClick="randomlinks(); return false;"

Upvotes: 1

Related Questions