简体   繁体   中英

Need help on a Search Form

First post on this site and i am hoping someone can help me. I created a search form on my site without a submit button. What i would like to happen is when the user clicks on the search bar it automatically redirects to a new page. I tried an attempt using Javascript but it does not seem to work. Hoping someone can help me out as i am not familiar with javascript.

<div id="searchbox">
<input type="text" name="search" placeholder="Search.." onClick="redirect('www.triphub.ca')">
</div>


</style>
<script>function redirect('www.triphub.ca')
 {
    window.location.href = www.triphub.ca;
</script>

Thank you

You could revise your function to

function redirect(url)
{ window.location.href = url; }

things inside () are variables and cannot be used as string (like you does wrapped words inside the single quote ' , also you are missing the } at the end of your javascript

Correct some of mistakes in your code.

 <div id="searchbox"> <input type="text" name="search" placeholder="Search.." onClick="redirect('www.triphub.ca')"> </div> <script> function redirect(url) { window.location.href = url; } </script> 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM