[SOLVED] Button issue on completed wiki viewer - Spoiler

[SOLVED] Button issue on completed wiki viewer - Spoiler
0

#1

Hi fellow campers,
I’m having a weird issue on my completed wiki viewer project. I have a form element with a search box and search button and another separate button that links to a random article.

My issue is that my separate random button gets a random article, only if the search field of my form is empty, otherwise it returns an article related to whatever is in the search field.

I’m not entirely sure whats causing this behaviour and hope someone might offer some help or suggestions as to what the problem might be.

Thanks.


#2

Hello. It looks like your button with ID #randombutton is actually submitting your form (which you do not intend to do). When a form is submitted you make an API call with the blank URL from the input field and it hangs in the browser.

An HTML peculiarity — if a tag does not have attr type=“button” it will submit the form in your HTML as if it were a type=“submit” button. So what would happen if you added type=“button” to your #randombutton?


#3

Thanks @Swoodend,
This has solved the problem :slight_smile:. I’ll remember to specify type in my buttons from now on. :thumbsup:


#4

That’s great news. Happy coding :slight_smile: