0

I have created a search box which search through Duck Duck Go, It's perfectly working but the problem is that when I click on search button without typing anything on text field it takes user to duck duck go search home page which I don't want here. Can someone help me to solve the problem so that whenevr i click on search button without typing anything the page remains the same Here is the code:

<form class="form-search" method="get" action="https://duckduckgo.com/">
            <input type="search" name="q" placeholder="Search or type web address">
            <button type="submit">Search</button>
            
        </form>
Social XD
  • 3
  • 1

1 Answers1

2

You can add required tag in input field.It will check that while submitting it should have some data in it.

<form class="form-search" method="get" action="https://duckduckgo.com/">
            <input type="search" name="q" placeholder="Search or type web address" required>
            <button type="submit">Search</button>
            
        </form>
devansh goyal
  • 71
  • 1
  • 6