javascript - getting value from input field and open a new link -
im new html && javascript coding im doing first steps , trying write search bar pass google input text
<script src="func.js"></script> <form name="googleseach"> <p align="center"><input name="searchtxt" id="searchtxt" type=search placeholder="google search"> <input type="submit" value="find" onclick="test()"></p> </form>
and javascript
function test(){ window.open("https://www.google.ru/webhp?newwindow=#q="+document.getelementbyid('searchtxt').value,"_self") }
well, thought should work no, not. what's proble?
believe want use
<form name="googleseach" onsubmit="test(event)">
instead of onclick.
also handler should cancel submit action. use location.href
instead of window.open
since you're trying open new url in same window.
Comments
Post a Comment