Monday, 15 June 2015

javascript - getting value from input field and open a new link -


HTML is completely new & amp; Amp; Javascript coding So now I'm taking my first step and trying to write a search bar that will pass through your input text

  & lt; Script src = "func.js" & gt; & Lt; / Script & gt; & Lt; Form name = "googleSeach" & gt; & Lt; P align = "center" & gt; & Lt; Input name = "searchTxt" id = "searchTxt" type = search placeholder = "Google search" & gt; & Lt; Input type = "submit" value = "search" onclick = "test ()" & gt; & Lt; / P & gt; & Lt; / Form & gt;  

and javascript

  function testing () {window.open ("https://www.google.ru/webhp?newwindow=#q= "+ Document.getElementById ('searchTxt'). Value," _self ")}  

Well, it should work, but no, it is not. What's the problem

Believe that you just want to use

  & lt ; Form name = "googleSeach" onsubmit = "test (event)" & gt;  

Instead of onClick.

In addition, your handler should probably abort the submit operation. Use location.href instead of window.open , because you are trying to open a new URL in the same window.


No comments:

Post a Comment