Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html>
- <body>
- <form id="myForm">
- <input type="text" id="txtSearch" />
- <input type = "submit" id = "btnSearch" value = "Search" onclick = "return searchURL();"/>
- </form>
- <script>
- //inhalt aus dem textfeld lesen
- var SearchInput = document.getElementById("txtSearch");
- //das Inputfeld soll ja auch auf [Enter] reagieren!
- document.getElementById("txtSearch").onkeypressed = function() {if(this.event.which === 13) searchURL()}
- //ich habe die documentwrites drin gelassen zum testen ohne reale Seiten
- // dafür window.location = ... mit "//" auskomentieren!
- function searchURL()
- {
- //wir wissen ja nicht op der user groß oder klein schreibt , ergo machen wir alles klein
- var x=SearchInput.value.toLowerCase()
- //besser als vergleichen ist ob string etwas enthält...user könnten ja ein leerzeichen anhängen
- if (x.includes("blume")) {
- document.write("da schnuppert wer");
- window.location = "https://www.bing.com/search?q=" + SearchInput.value;
- }
- else
- if (x=="elefant") {
- document.write("tröt");
- window.location = "https://de.search.yahoo.com/?p=" + SearchInput.value;
- }
- else {
- document.write("bäh");
- window.location = "https://www.google.de/?q=" + SearchInput.value;
- }
- }
- </script>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement