0

im completely new to html && javascript coding so now im doing my first steps and trying to write a search bar which will pass google your 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 it should work but no, it does not. What's the proble?

0

1 Answer 1

1

Believe you just want to use

<form name="googleSeach" onsubmit="test(event)"> 

Instead of onclick.

Also your handler should probably cancel the submit action. Also use location.href instead of window.open since you're trying to open the new URL in the same window.

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

Sign up to request clarification or add additional context in comments.

1 Comment

;) Sorry for rushing it the first time

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.