+ 2
Why isn't this code working?
3 Answers
+ 3
In Html, set
<form name="form" onsubmit="sel(event)">
In Javascript, set
function sel(e) {
e.preventDefault();
var sela = document.getElementById("pet");
var text = sela.options[sela.selectedIndex].text;
if(text !== '') {
window.location.href= `https://www.google.com/search?q=${text}`
}
}
Check out the solotion:
https://code.sololearn.com/W3Dh91C746TS/?ref=app
+ 4
var sel = document.getElementById("pet");
var text = sel.options[sel.selectedIndex].text;
if(text !== '') {
window.location.href= `https://www.google.com/search?q=${text}`
}
^That should do it. I'm not sure sololearn will allow you to redirect to third party websites though.
+ 1
Thanks