jquery - Script Sends me to search.html? instead of the desired website -
alright, basically, index.html contains search bar doesn't it's supposed to- when enter pressed, should take me google.com/(gsecode)q=(what typed), instead sends me index.html? instead of want use jquery script trigger button click. have looked solutions don't seem work.
html:
<input type="text" id="text-box" size="size"> <input type="submit" id="submit" onclick="(javascriptcode)" name="google search">
jquery:
document.getelementbyid("id_of_button").onclick = function() {clickfunction()}; function clickfunction() { document.location.href = 'https://cse.google.com/cse?cx=009002930969338329916:kta6o_isob0&q=' + escape(document.getelementbyid('search-box').value) } $("text-box").keyup(function(event){ if(event.keycode === 13){ $("#submit").click(); } });
i'm not sure if code loose example or final product, have lot of things wrong here. i'm going post example works instead, , can follow that.
your ids not named or matching jquery selectors. have onclick event isn't needed
$(document).on('click', '#mybuttonid', function() { clickfunction(); }); function clickfunction() { alert('normally run document location href, in jsfiddle so...'); document.location.href = 'https://cse.google.com/cse?cx=009002930969338329916:kta6o_isob0&q=' + escape($('#mysearchboxid').val()); } $('#mysearchboxid').keyup(function(event){ if(event.keycode === 13){ $("#mybuttonid").click(); } });
and
<input type="text" id="mysearchboxid" size="30"> <input type="submit" id="mybuttonid" value="google search">
Comments
Post a Comment