hi, i have this little issue, i'm trying to make the SIMPLEST google search for a cool little project and when i try to load a link via JS on form submit, it doesn't do anything. Changing the submit button to a type="button" and adding the event to that button onclick="function()" will work, but add the onsubmit="function()" to the <form> tag won't work. Can someone tell me why? Or how I can get it to work?
Why wont' this work?
... and why does this work?HTML Code://JS file function showSearchWord() { var googleSearch = "http://www.google.com/search?q="; var formsValue = document.getElementById("googleForm").value; window.location = googleSearch + formsValue; } //html file <form name="myForm" onsubmit="showSearchWord()"> <ul> <li> <input type="text" id="googleForm" name="inputForm" /> <input type="submit" value="Search" /> </li> </ul> </form>
HTML Code://JS file function showSearchWord() { var googleSearch = "http://www.google.com/search?q="; var formsValue = document.getElementById("googleForm").value; window.location = googleSearch + formsValue; } //html file <form name="myForm"> <ul> <li> <input type="text" id="googleForm" name="inputForm" /> <input type="button" value="Search" onclick="showSearchWord()"/> </li> </ul> </form>