I have some code here:
<html>
<script type="text/javascript">
document.getElementById('myElement').onclick = function ()
{
var searchterm = document.getElementById('bereich').value;
document.href("http://www.google.com/serach?q=" + searchterm);
}
</script>
<body>
<center>
<img src="https://www.google.de/images/srpr/logo3w.png"><br>
<input type="text" name="q"> <input type="button" value="Search" onclick="startSearch()">
</center>
which does not work. I know this is such a noob stuff at all, but I don´t know javascript. Can anyone help me please?
Addition:
I also tried:
<html>
<body>
<center>
<img src="https://www.google.de/images/srpr/logo3w.png"><br>
<input type="text" name="q"> <input type="button" value="Search" onclick="startSearch()">
</center>
<script type="text/javascript">
window.onload = function(){
document.getElementById('myElement').onclick = function ()
{
var searchterm = document.getElementById('bereich').value;
document.href = "http://www.google.com/serach?q=" + searchterm;
}
};
and:
<html>
<body>
<center>
<img src="https://www.google.de/images/srpr/logo3w.png"><br>
<input type="text" name="q"> <input type="button" value="Search" name="searchButton" onclick="startSearch()">
</center>
<script type="text/javascript">
function triggerGoogleSearch()
{
var searchterm = document.getElementById('bereich').value;
document.href("http://www.google.com/serach?q=" + searchterm);
}
document.getElementById('searchButton').onclick = triggerGoogleSearch();
</script>
</body>
</html>
Change this:
to this:
and change this:
to this:
And also add
id="bereich"to your<input type="text" name="q">like this:if you want to find it by getElementById.
Also, change the url from:
to this:
UPDATE:
Actually never mind all of those corrections and forget about JavaScript!
Just make a simple HTML form:
See THIS DEMO.
I think that we were all trying to fix your code and completely missed a much simpler solution. 🙂