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.

http://jsfiddle.net/bvaughn/fr35mpgf/2/


Comments

Popular posts from this blog

node.js - Mongoose: Cast to ObjectId failed for value on newly created object after setting the value -

[C++][SFML 2.2] Strange Performance Issues - Moving Mouse Lowers CPU Usage -

ios - Possible to get UIButton sizeThatFits to work? -